Hacker News new | ask | show | jobs
by userbinator 4536 days ago
If I've interpreted this correctly, it means that all values between 256 and 65535 can't be encoded this way since they all have the form

0x0000nn00

with a nonzero nn, and those are the bits that can't be gotten to from rotating.

2 comments

Anything of the form 0x0000nn00 is representable, as it has at most eight contiguous non-zero bits starting at an even bit position (i.e. these values are 0x000000nn rotated right by 24). Maybe you're wondering how a rotation of 24 can be encoded in four bits? To get the rotation amount, you double the value of the four-bit field. Only even rotation counts are representable.
Thanks, overlooked that detail. Very interesting encoding scheme.
Sure they can, by setting the rotate bits to 0xC (1100). Have a play with the interactive widget near the bottom of the article.

Interestingly, there is some redundancy with this encoding meaning you can't represent a full 2^12 unique values. Eg 0x1 could be represented by 0x1 and 0x0 in the rotate field, 0x4 with 0x1 in the rotate field, 0x10 with 0x2, or 0x40 with 0x3. The same applies for every other combination - this means that there are only (2^12)/4 = 1024 unique values that are representable in total.

You didn't do that math right. Out of every 256 values at a particular offset, only a quarter of them are under 64 and can be encoded with rotate+1.

Doing a quick brute force test, it appears that there are 3073 unique values. I suppose that makes sense. Each new rotate introduces 192 new values that have at least one of the new bits set, and 192 * 16 = 3072. Then you have the number 0.