Bit Hacks
Prev: bentley-rules-for-optimizing-work Next: assembly-language—computer-architecture
Binary Representation
Let be a -bit computer word.
So: 0b10010110
would represent 128 + 16 + 4 + 2 or 150 if it was unsigned.
The signed integer (two’s complement) would be:
So: 0b10010110
would be -128 + 16 + 4 + 2 or -106.
Thus, 0b00000000
would be 0.
And 0b11111111
would be -1.
Thus, x + ~x = -1
, or -x = ~x + 1
.
Prev: bentley-rules-for-optimizing-work Next: assembly-language—computer-architecture