What is 2's complement and how do I use it.?

Since the Pedestal can be a Positive or Negative number, it is written in 2's complement so that when binary addition is used to add it to the actual offset, the result is correct.  A positive 2's complement number is the binary equivalent of the number.  A negative 2's complement number is the binary equivalent of a number that when added to the positive version of the same value, equals zero.  Remember, for pedestal correction, the 13th bit is the sign bit.

Adding a 2's complement Example:  2 + (-2) = 0,  [ 0000 0000 0010   +   1111 1111 1110 =  1 0000 0000 0000] .
Looking at the first 12 bits of data since the 13th bit is ignored,  2 + 4094  = 4096  or  0 for 12 bits of Data

To calculate the 2's complement, invert the binary equivalent of the number by changing all the ones to zeros and all zeros to ones.  Then add 1 to that value.

Example:
1)  To set the offset to -100,  Write 100 in binary for the number of  DATA bits required.  [ 12 bits  0000 0110 0100 ]
2)  Change all 1's to 0's and 0's to 1's:   [  1111 1001 1011 ]
3)  Add 1 to this number, which becomes:   [ 1111 1001 1100 ]
     Include the 13th bit to show it's a negative number when writting to pedestal memory. [ 1 1111 1001 1100 ]
     If the 13th bit was 0 (positive), this offset would be be + 3996 instead of -100

Back to Technical Questions