Here's a faster version of toVint, for at least some right arguments:
toVint2=: [: (({."1 ,. 1:) #&, 255 ,. {:"1) 0 255 #: ]
Here's an implementation of fromVint:
fromVint=: 255&~: +/;.2 ]
Thanks,
--
Raul
On Mon, Dec 29, 2014 at 12:12 PM, 'Pascal Jasmin' via Programming
<[email protected]> wrote:
> A common design decision is how large to make a field. For many numbers, we
> think that a byte will be large enough to hold practical values, but one day
> we will find out that it is not. This is essentially the Y2k problem, or
> year 2032 issue.
>
> A simple variable integer coding (tied to byte ranges)
>
> toVint =: [: ; (255&| ,~ 255 #~ <.@%&255) each
>
> toVint 566 44
> 255 255 56 44
>
> It now takes 3 bytes to store 566, and one byte to store 44.
>
> the challenge is to write fromVint such that
>
>
> 566 44 -: fromVint 255 255 56 44
>
> as an extra challenge, is there a way to write toVint or fromVint such that
> it is faster than using intermediate boxing?
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm