Alright
Addition of binary, hexadecimal and octal integers
Addition of binary is conducted in the same way as in the regular decimal number system. Let’s compare them side by side to get a clear understanding.
Example:
1
1 6 3
+ 4 5
-------
2 0 8
Decimal (base-10)
1 1 1 1 1
0 0 1 1 0 1 1 0
+ 0 1 1 1 0 0 1 1
-----------------
1 0 1 0 1 0 0 1
Binary (base-2)
1
6 B
+ 4 F
-----
B A
Hexadecimal (base-16)
1
3 5 4
+ 1 1 4
-------
4 7 0
Octal (base-8)
In the decimal number system a carry is generated when the sum is > 910. This is treated the same way in the binary number system; were a carry is generated when the sum is > 12, meaning 1 + 1 = 102, or 1 + 1 + 1 = 112.
The hexadecimal and octal number system generate a carry when the sum is > 1510 and > 710 respectively.
Base | Carry generated when sum is > |
10 (Decimal) | 9 |
2 (Binary) | 1 |
16 (Hexadecimal) | F (1510) |
8 (Octal) | 7 |
The additions in the systems hexadecimal and octal number system above that generates a carry are the following:
- B16 + F16 = 1110 + 1510 = 2610 = 1A16
- 48 + 48 = 810 = 108
Subtraction of binary, hexadecimal and octal integers
Subtraction can also be done in the same way as the decimal number system. The borrow number is treated the same as decimal numbers. In the decimal number system, you borrow a 1 from the number to the left. This is then worth 10 times as much when it’s moved to the right, e.g 1010. In the binary number system, you also borrow from the left, but the number worth is 2 times as much when moved.
In any base b, when borrowing, the borrowed value is equal to b in decimal. For example, in binary (base-2), borrowing means adding 210, in hexadecimal (base-16), it means adding 1610, and in octal (base-8), it means adding 810.
No matter what base b you have, you always borrow 10b.
Example:
10
1 6 3
- 4 5
-------
1 1 8
Decimal (base-10)
2 2<-210
1 1 1 1 1 1 1 0
- 0 1 0 1 0 0 1 1
-----------------
1 0 1 0 1 0 1 1
Binary (base-2)
16<-1610
6 B
- 4 F
-----
1 C
Hexadecimal (base-16)
8<-810
3 5 4
- 1 1 5
-------
2 3 7
Octal (base-8)