3 ms·
How does [0xFF, 0xFF, 0xFF, 0xFF], interpreted as a UInt32 turn into 16777215? I would have guessed 4294967295
by grimlck 12y ago
How does
[0xFF, 0xFF, 0xFF, 0xFF], interpreted as a UInt32
turn into 16777215?
I would have guessed 4294967295
- Hannan 12y agoI assume it's just a typo/incomplete edit; his graphic directly below has the bit representation 00000000111111111111111111111111 indicating [0x00, 0xFF, 0xFF, 0xFF].
- shurcooL 12y agoIt is 4294967295. http://play.golang.org/p/r8LHo8mfc9 http://play.golang.org/p/r8LHo8mfc9
- codygman 12y agoYep (credit to bkirwi): λ> import Data.Bits λ> let integerWithBytes = foldr (\byte acc -> (acc `shiftL` 8) + fromIntegral byte) 0 λ> integerWithBytes [0xFF, 0xFF, 0xFF, 0xFF] 4294967295