Pascal, Thanks for sharing. Can you also share a potential use case?
I had to remind myself about the size of integers (4 bytes) on 32-bit. Will this only save space on numbers less than 1019? NB. 4 bytes toVint2 1019 255 255 255 254 NB. 5 bytes toVint2 1020 255 255 255 255 0 Are you looking for the savings in terms of disk space (saving it to a file) or working memory? 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
