Why does
((255<<24)|(255<<16)|(255<<8)|255)>>>0
equals 4294967295 when
Math.pow(256,4)
equals 4294967296?
Notice that the bitwise operation is one short. Why is this?!
Because zero takes up a binary value.
4294967296 is the number of "slots" that 32 bits gives you, 4294967295 is the decimal number occupying highest slot.
Because the first one is 2^32-1, and the second one is 2^32? You know that with the first "statement" you are setting to 1 the first 32 bits of a value, right?
In 32 bits, the first bit is "valued" 1, the second 2, the third 4... The 32th 2147483648. Their sum is 4294967295 :-)
Let's make an example with 8 bits.
Math.pow(256,1) == 256
1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 = 255.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With