in SQL Server books online, there is an example for explaining bitwise not operator which made me confused:
The binary representation of 170 (a_int_value or A) is 0000 0000 1010 1010. Performing the bitwise NOT operation on this value produces the binary result 1111 1111 0101 0101, which is decimal -171.
As an integer is 4 bytes in SQL Server shouldn't it be:
170: 0000 0000 0000 0000 0000 0000 1010 1010 (0x000000AA)
and
~170 = -171 : 1111 1111 1111 1111 1111 1111 0101 0101 (0xFFFFFF55)
Example says the bitwise not operator gives the result: 1111 1111 0101 0101 which is 0xFF55 and if we convert it to int its totally a different integer:
Select cast(0xFF55 as int)
--> 65365
if it was smallint then the example would be true:
Select cast(0xFF55 as smallint)
--> -171
Does the example missed first 2 bytes of 1's or am I misunderstanding something?
Thanks,