Sat. Jan 21st, 2023

Binary arithmetic

Addition

Binary addition is calculated by working from right to left and adding columns as you go. If the column adds up to more than 1, then the excess (in binary format) should be carried to the left:

1286432168421
Number 101100111
Number 201110000
Carry11
Answer11**0*10111

* 1 plus 1 is two. In binary, this is ’10’. So write a zero in the column, and carry ‘1’ to the next column.

** 1 plus 2 is three, which in binary is ’11’. So write a ‘1’ in the current column, and carry ‘1’ to the next column.

Subtraction

Binary subtraction is performed by first converting the number to be subtracted into a negative value, and then adding this to the initial value.

For example, to calculate 106 – 24, you would actually perform 106 + (-24).

Subtraction implies that the binary values are signed, meaning the column values look like this:

-1286432168421

In signed binary, the most significant bit (MSB) is negative. This means that using 8 bits we can represent values from -128 to +127. See here for how to convert a positive number into a negative value.

The example given above would work out as:

-1286432168421
Number 1 (106)01101010
Number 2 (-24)11101000
Carry111
Result0 *1010010

*NB in this example, the overflow doesn’t matter

Answer = 64 + 16 + 2 = 82

Multiplication

Multiplication is performed in a similar manner to in standard long multiplication – see the annotated example below. Each row is essentially zero or 1 times the original number, although successively shifted to the left. (The green row in the example).