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¶
10410+ 210= 0110 10002+ 0000 00102= 0110 10102= 10610
As the result isn’t greater than 0111 11112, for this operation didn’t occurred overflow.
10410+ 2410= 0110 10002+ 0001 10002= 1000 00002= 010
As the result is greater than 0111 11112the result is wrong and occurred overflow.
3.2. Subtraction¶
-10410- 210= -(10410+ 210)= -(0110 10002+ 0000 00102) = 1110 10102= - 10610
As the result isn’t greater than 0111 11112, for this operation didn’t occurred overflow.
-10410- 2410= -(10410+ 2410) = -(0110 10002+ 0001 10002) = 1000 00002
As the result is greater than 0111 11112 the result is wrong and occurred overflow.
-10410+ 2410= -(10410- 2410) = -(0110 10002- 0001 10002) = 1101 00002
3.3. Multiplication¶
210* 6010= 0000 00102* 0011 11002= 0111 10002= 12010
-210* 6010= -0000 00102* 0011 11002= -0111 10002= 1111 10002= - 12010
In none of the cases occurred overflow.
3.4. Division¶
6010/210= 0011 11002/ 0000 00102= 0001 11102= 3010
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, y2= ( \(2^n\) - x)2. For example we are working with 3 bits and we want to know the two complement of -0102, doing the operation,
y2 = 10002 – 0102 = 1102, and this is -0102 represented in two complement.
Adding and subtracting numbers is easy.
310 – 210 = 0112 – 0102 = 0112 + (10002 - 0102) =0112 + 1102 = 10012 = 0102, in this case we have to discard the MSB, the result is correct as the operands had different sign.
310 +210 = 0112 + 0102 = 1012 , the result is wrong as the sign of the operand are equal and the sign of the result is different, occurred overflow.
-310 – 210 = 1012 + 1102 = 10112 , the result is wrong as the sign of the operand are equal and the sign of the result is different, occurred overflow.
-310 – 110 = 1012 + 1112 = 11002 = 1002, 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 |