Training Computer Engineering Number Systems & Binary Arithmetic
1 / 5

Number Systems & Binary Arithmetic

24 min Computer Engineering

Number Systems & Binary Arithmetic

Computers operate in binary (base 2). Understanding number system conversions and binary arithmetic is essential for computer engineering.

Positional Notation

A number in base $b$:

$$(d_n d_{n-1} \dots d_1 d_0)_b = d_n b^n + d_{n-1} b^{n-1} + \cdots + d_1 b + d_0$$

Common Bases
BaseNameDigits
2Binary0, 1
8Octal0–7
10Decimal0–9
16Hexadecimal0–9, A–F
Example 1

Convert $(1101\,0110)_2$ to decimal.

$1(128) + 1(64) + 0(32) + 1(16) + 0(8) + 1(4) + 1(2) + 0(1) = 128 + 64 + 16 + 4 + 2 = 214$

Example 2

Convert decimal 200 to binary.

$200 ÷ 2 = 100$ R $0$
$100 ÷ 2 = 50$ R $0$
$50 ÷ 2 = 25$ R $0$
$25 ÷ 2 = 12$ R $1$
$12 ÷ 2 = 6$ R $0$
$6 ÷ 2 = 3$ R $0$
$3 ÷ 2 = 1$ R $1$
$1 ÷ 2 = 0$ R $1$

Read remainders bottom-up: $(1100\,1000)_2$

Example 3

Add $(1011)_2 + (0111)_2$ in binary.

\begin{align}1011& \\ +\;0111& \\ \hline 10010&\end{align}

Result: $(10010)_2 = 18$ in decimal. Check: $11 + 7 = 18$ ✓

Practice Problems

1. Convert $(10110101)_2$ to decimal.
2. Convert decimal 255 to binary.
3. Convert decimal 156 to hexadecimal.
4. Convert $(\text{3F})_{16}$ to decimal.
5. Convert $(\text{3F})_{16}$ to binary.
6. Add: $(1100)_2 + (1010)_2$.
7. Subtract: $(1010)_2 - (0011)_2$.
8. Multiply: $(101)_2 \times (11)_2$.
9. Convert $(347)_8$ to decimal.
10. How many values can an 8-bit unsigned integer represent? What is the maximum value?
11. Two's complement: represent $-5$ in 8-bit binary.
12. What is the range of an 8-bit two's complement integer?
Show Answer Key

1. $128+32+16+4+1 = 181$

2. $(11111111)_2$

3. $156 = 9 \times 16 + 12$; $(\text{9C})_{16}$

4. $3 \times 16 + 15 = 63$

5. $3 = 0011$, $F = 1111$; $(00111111)_2$

6. $(10110)_2 = 22$

7. $(0111)_2 = 7$

8. $(1111)_2 = 15$; check: $5 \times 3 = 15$ ✓

9. $3(64) + 4(8) + 7 = 192 + 32 + 7 = 231$

10. $2^8 = 256$ values; max $= 255$

11. $5 = 00000101$; invert: $11111010$; add 1: $11111011$

12. $-128$ to $+127$