December 2013
Beginner
576 pages
16h 4m
English
The ones complement operator is a unary operator, and its effect is to simply “flip” the bits of its operand. Each bit of the operand that is a 1 is changed to a 0, and each bit that is a 0 is changed to a 1. The truth table is provided here simply for the sake of completeness.
b1 ~b1————————0 11 0
If w1 is a short int that is 16 bits long and is set equal to hexadecimal a52f, taking the ones complement of this value produces a result of hexadecimal 5ad0:
w1 1010 0101 0010 1111 0xa52f~w1 0101 1010 1101 0000 0x5ad0
The ones complement operator proves useful when you don’t know the precise bit size of the quantity that you are dealing with in an operation, and ...
Read now
Unlock full access