# Binary Arithmetic

## Signed Binary Numbers

### Sign and Magnitude

Where do you put the sign bit?
Is the leftmost or the rightmost bit better?

We need an extra step to determine the sign of the result of an addition. Why?

Both positive and negative zero exist in this representation. What does this
mean for the programmer?

### Two's Complement

Form negative numbers by taking the complement (apply the not operator) of the
corresponding positive number and adding one.
Eight bit two's complement binary numbers:

-4_{ten} = not 00000100 + 1_{two} = 11111011 + 1_{two} = 11111100_{two}
-128_{ten} = not 10000000 + 1_{two} = 01111111 + 1_{two} = 10000000_{two}

128_{ten} cannot be represented as an eight bit two's complement binary
number!

The leftmost bit is the sign bit. If it is one, the number is negative and its
decimal value can be found by taking the complement and adding one. This is
equivalent to subtracting one and then taking the complement.

Eight bit two's complement binary numbers:

00001000_{two} = 8_{ten}
10001000_{two} = not 10001000 + 1_{two} = 01110111 + 1_{two} = 01111000_{two} = -120_{ten}

CSE 378 Spring 2002 - Section 1