No history yet

Number Systems

The Language of Computers

We live in a decimal world. We count with ten digits (0 through 9), which comes naturally because we have ten fingers. This system, also called base-10, works by assigning value to a digit based on its position. In the number 327, the 7 is in the ones place (10010^0), the 2 is in the tens place (10110^1), and the 3 is in the hundreds place (10210^2).

Computers, however, don't have fingers. They have transistors, which can be either on or off. This two-state system is perfect for a different kind of counting: binary.

Lesson image

Digital electronics rely on a few key number systems to represent and process information. While they all handle the same values, each has a specific purpose.

The Core Systems

Beyond the familiar decimal system, there are three other systems you'll constantly encounter in digital electronics and programming.

Binary (Base-2): This is the native language of all digital systems. It uses only two digits: 0 and 1. Each position represents a power of 2. For example, the binary number 11011101 isn't one thousand, one hundred and one. It's (1×23)+(1×22)+(0×21)+(1×20)(1 \times 2^3) + (1 \times 2^2) + (0 \times 2^1) + (1 \times 2^0), which equals 8+4+0+18 + 4 + 0 + 1, or 13 in decimal.

Octal (Base-8): Uses eight digits (0–7). Octal is sometimes used as a more compact way to represent binary numbers, because each octal digit corresponds exactly to a group of three binary digits. It's less common today but still appears in some systems, like file permissions on Unix-based computers.

Hexadecimal (Base-16): This is the most common shorthand for binary. It uses 16 symbols: the digits 0–9 and the letters A–F to represent values 10 through 15. Each hexadecimal digit corresponds to a group of four binary digits, making it a very efficient way to display long binary strings. You'll see it used for memory addresses, color codes (like #FF0000 for red), and error codes.

DecimalBinaryOctalHexadecimal
0000000
1000111
2001022
3001133
4010044
5010155
6011066
7011177
81000108
91001119
10101012A
11101113B
12110014C
13110115D
14111016E
15111117F

Converting Between Bases

Being able to switch between these systems is a crucial skill. The process is straightforward once you understand positional values.

To convert any number to decimal, you multiply each digit by its base raised to its positional power, then sum the results. Positions are counted from the right, starting at 0.

Let's convert the hexadecimal number $1AF$ to decimal:

1AF16=(1×162)+(A×161)+(F×160)=(1×256)+(10×16)+(15×1)=256+160+15=43110\begin{aligned} 1AF_{16} &= (1 \times 16^2) + (A \times 16^1) + (F \times 16^0) \\ &= (1 \times 256) + (10 \times 16) + (15 \times 1) \\ &= 256 + 160 + 15 \\ &= 431_{10} \end{aligned}

To convert a decimal number to another base, you use repeated division. Divide the decimal number by the target base, note the remainder, and then divide the result (the quotient) by the target base again. Repeat until the quotient is 0. The new number is the sequence of remainders, read from bottom to top.

Let's convert the decimal number 43 to binary:

Binary Arithmetic

Since computers operate in binary, they must also perform arithmetic in binary. The rules are much simpler than in decimal.

For addition: $0 + 0 = 0$ $0 + 1 = 1$ $1 + 0 = 1$ $1 + 1 = 0$, carry the 1

Let's add 10111011 (11) and 01100110 (6). We work from right to left, just like in decimal addition.

  1 1 1   (carry)
  1 0 1 1   (11)
+ 0 1 1 0   (6)
-----------
1 0 0 0 1   (17)

Subtraction, multiplication, and division also have binary equivalents. Subtraction involves "borrowing" from the next place value, similar to decimal. Multiplication is a series of shifts and additions, while division is a series of shifts and subtractions. These operations form the bedrock of all calculations a computer performs.

Now that you've seen the different ways numbers are represented, let's review the key terms.

Time to test your knowledge on these foundational concepts.

Quiz Questions 1/5

Why do computers primarily use the binary number system?

Quiz Questions 2/5

In which of the following applications would you most likely encounter a hexadecimal number?

Understanding how to work with binary, decimal, octal, and hexadecimal systems is the first step in understanding digital logic. Every complex operation a computer performs ultimately boils down to these simple numbers and rules.