Number 65535 – Significance in Computing

32-bitarithmeticbinarybitwise-operatorsnumbers

2¹⁶-1 & 2⁵ = 2⁵ (or? obviously ?)

A developer asked me today what is bitwise 65535 & 32 i.e. 2¹⁶-1 & 2⁵ = ?
I thought at first spontaneously 32 but it seemed to easy whereupon I thought for several minutes and then answered 32. 32 seems to have been the correct answer but how? 65535=2¹⁶-1=1111111111111111 (but it doesn't seem right since this binary number all ones should be -1(?)), 32 = 100000
but I could not convert that in my head whereupon I anyway answered 32 since I had to answer something. Is the answer 32 in fact trivial? Is in the same way 2¹⁶-1 &
2⁵-1 =31? Why did the developer ask me about exactly 65535?

Binary what I was asked to evaluate was 1111111111111111 &
100000 but I don't understand why 1111111111111111 is not -1.
Shouldn't it be -1? Is 65535 a number that gives overflow and how do I know that?

Best Answer

The number is treated as an unsigned integer in this case which means all bits set will not produce -1 (if it were signed then yes, you would be correct). So all 16 bits set will give you 65535.

Interestingly enough though, signed state isn't a factor when doing logic bit-operations. Bits are themselves not signed as they are the lowest component in a computer. It's specified by the cpu operation if the bits in ex. a register will be treated signed or unsigned.

Negative numbers are produced by setting the most significant bit (MSB) to true IF the number is treated as signed (which "side", or which outer bit will be set varies depending on cpu architecture, ie. big-endian / little-endian) .

Related Topic