4 ms·
Perhaps totally unrelated, but there is a curious property of 1,000,001 I revisited yesterday that only bit me while learning Erlang. 1> <<"A">>. <<"A">>
by arh68 11y ago
Perhaps totally unrelated, but there is a curious property of 1,000,001 I revisited yesterday that only bit me while learning Erlang.
1> <<"A">>.
<<"A">>
2> <<65>>.
<<"A">>
3> <<01000001>>.
<<"A">>
It would appear this <<..>> syntax parses binary numbers, as 65 is indeed 0b1000001. But the next number in binary is not "B" like I thought it would be.
1> <<01000001>>.
<<"A">>
2> <<01000010>>.
<<"J">>
As it turns out, the low bits of a million and one correspond exactly to the low bits of 0b1000001 = 65, "A". This seems incredibly unlikely. That's why a million and ten corresponds to "J", and a million and two corresponds to "B".
* (format t "~2R" 01000001)
11110100001001000001
* (format t "~2R" 65)
1000001
* (format t "~2R" 01000010)
11110100001001001010
3> <<01000002>>.
<<"B">>
- cperciva 11y agothe low bits of a million and one correspond exactly to the low bits of 0b1000001 = 65, "A". This seems incredibly unlikely Not as unlikely as it seems. Ignore the "and one" part, and the question is simply why 10^6 is 64 modulo 256; but since 10^6 = 5^6 * 2^6 is a multiple of 64, it's must be one of {0, 64, 128, 192} modulo 256, which takes "incredibly unlikely" down to "one out of four possibilities". (Going a bit further, you can rule out 0 and 128 because 5^6 is obviously odd, and you can rule out 192 because 5^6 is an odd square. But the most important part is that X000000 base 10 is immediately required to be XX000000 base 2 modulo 256.)