# 3. Basics of Digital Systems - Mathematical Operations with the Binary Base¶

Operations with binary base are equal the decimal base. The difference is when we need to store numbers in a finite amount of bits. Let’s do some operations with 8 bits, where the MSB is the signal bit and the others 7 bits are the bits of numerical value.

## 3.1. Sum¶

104_{10}+ 2_{10}= 0110 1000_{2}+ 0000 0010_{2}= 0110 1010_{2}= 106_{10}

As the result isn’t greater than 0111 1111_{2}, for this operation didn’t occurred overflow.

104_{10}+ 24_{10}= 0110 1000_{2}+ 0001 1000_{2}= 1000 0000_{2}= 0_{10}

As the result is greater than 0111 1111_{2}the result is wrong and occurred overflow.

## 3.2. Subtraction¶

-104_{10}- 2_{10}= -(104_{10}+ 2_{10})= -(0110 1000_{2}+ 0000 0010_{2}) = 1110 1010_{2}= - 106_{10}

As the result isn’t greater than 0111 1111_{2}, for this operation didn’t occurred overflow.

-104_{10}- 24_{10}= -(104_{10}+ 24_{10}) = -(0110 1000_{2}+ 0001 1000_{2}) = 1000 0000_{2}

As the result is greater than 0111 1111_{2} the result is wrong and occurred overflow.

-104_{10}+ 24_{10}= -(104_{10}- 24_{10}) = -(0110 1000_{2}- 0001 1000_{2}) = 1101 0000_{2}

## 3.3. Multiplication¶

2_{10}* 60_{10}= 0000 0010_{2}* 0011 1100_{2}= 0111 1000_{2}= 120_{10}

-2_{10}* 60_{10}= -0000 0010_{2}* 0011 1100_{2}= -0111 1000_{2}= 1111 1000_{2}= - 120_{10}

In none of the cases occurred overflow.

## 3.4. Division¶

60_{10}/2_{10}= 0011 1100_{2}/ 0000 0010_{2}= 0001 1110_{2}= 30_{10}

If the division results in a decimal number, the decimal places are discarded.

## 3.5. Two Complement¶

The way we do arithmetic operations in a paper, adding transport numbers and deciding which number is greater to change the signal and perform a subtraction, is difficult to implement in a digital system. To overcome that there is another way to represent finite binary numbers and it’s called two complement. It is easier to perform calculations of sum and subtraction using two complement representation.

First we define with how many bits we are working. After that we perform an operation to find the two complement of a negative number. If you have to do the complement of a number x of n bits, the operation is this, y_{2}= ( \(2^n\) - x)_{2}. For example we are working with 3 bits and we want to know the two complement of -010_{2}, doing the operation,

y_{2} = 1000_{2} – 010_{2} = 110_{2}, and this is -010_{2} represented in two complement.

Adding and subtracting numbers is easy.

3_{10} – 2_{10} = 011_{2} – 010_{2} = 011_{2} + (1000_{2} - 010_{2}) =011_{2} + 110_{2} = 1001_{2} = 010_{2}, in this case we have to discard the MSB, the result is correct as the operands had different sign.

3_{10} +2_{10} = 011_{2} + 010_{2} = 101_{2} , the result is wrong as the sign of the operand are equal and the sign of the result is different, occurred overflow.

-3_{10} – 2_{10} = 101_{2} + 110_{2} = 1011_{2} , the result is wrong as the sign of the operand are equal and the sign of the result is different, occurred overflow.

-3_{10} – 1_{10} = 101_{2} + 111_{2} = 1100_{2} = 100_{2}, the result is correct as the sign of the operand are equal and the sign of the result is equal.

Binary number | 3 bits complement two |
---|---|

011 | 011 |

010 | 010 |

001 | 001 |

000 | 000 |

100 | 111 |

101 | 110 |

110 | 101 |

111 | 100 |