๐Ÿ’ป Computer Science Guide

Understanding Binary Numbers

A complete guide to the binary number system โ€” how it works, how to convert between binary and decimal, and why every computer in the world uses it.

โœ๏ธ By Mwalimu Ronny ๐Ÿ“š Primary & Secondary Level โฑ๏ธ 10 min read

What Is the Binary Number System?

The binary number system is a way of counting that uses only two digits: 0 and 1. Every number, letter, image, sound and video stored or processed by a computer is ultimately represented using only these two digits.

The number system we use in everyday life is called the decimal system (also called base 10), because it uses ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. Binary is called base 2 because it uses only two digits.

Binary was not invented for computers โ€” it has been studied by mathematicians for centuries. But it became the foundation of modern computing because electronic circuits have exactly two stable states: on (represented as 1) and off (represented as 0). This makes binary the natural language of all digital electronics.

Key fact: A single binary digit (a 0 or a 1) is called a bit, which is short for binary digit. Eight bits together form a byte. Your phone's storage is measured in gigabytes โ€” billions of bytes โ€” all made up of individual 0s and 1s.

Why Do Computers Use Binary?

You might wonder: why not build computers that use the decimal system like humans do? The reason is physical. Inside every computer, data is stored and processed using tiny electronic switches called transistors. A transistor has two states โ€” it is either conducting electricity (on) or not conducting electricity (off). These two states map perfectly to 1 and 0.

If we tried to build a decimal computer, we would need transistors that could reliably hold ten different voltage levels โ€” one for each digit from 0 to 9. This is extremely difficult to do reliably, especially at the billions-per-second speeds modern computers operate at. Binary is robust, fast and error-resistant, which is why it has been the foundation of computing since the first electronic computers in the 1940s.

Everything a computer does โ€” running an application, displaying a webpage, playing a video, storing a photograph โ€” is ultimately just billions of transistors switching between on and off, billions of times per second.

Place Values in Binary

In the decimal system, each digit position represents a power of 10. The rightmost digit is the ones place (10โฐ = 1), the next is the tens place (10ยน = 10), then hundreds (10ยฒ = 100), and so on.

In binary, each digit position represents a power of 2 instead. The rightmost position is 2โฐ = 1, the next is 2ยน = 2, then 2ยฒ = 4, 2ยณ = 8, 2โด = 16, 2โต = 32, 2โถ = 64, and 2โท = 128.

This is the bit position table you need to memorise for KCSE Computer Studies:

2โท
128
bit 7
2โถ
64
bit 6
2โต
32
bit 5
2โด
16
bit 4
2ยณ
8
bit 3
2ยฒ
4
bit 2
2ยน
2
bit 1
2โฐ
1
bit 0

When a binary digit in a particular position is 1, you include that position's value in the total. When it is 0, you do not. This is the key rule for all binary-to-decimal conversions.

Converting Binary to Decimal

To convert a binary number to decimal, write out the bit positions, place the binary digits under their positions, then add up the values of all positions that have a 1.

Worked Example 1 โ€” Convert 1011โ‚‚ to decimal

1
Write the bit positions from right to left: 8, 4, 2, 1
2
Place the binary digits under the positions: 1โ†’8, 0โ†’4, 1โ†’2, 1โ†’1
3
Multiply each bit by its position value: (1ร—8) + (0ร—4) + (1ร—2) + (1ร—1)
4
Add the results: 8 + 0 + 2 + 1 = 11

Answer: 1011โ‚‚ = 11โ‚โ‚€

Worked Example 2 โ€” Convert 10110100โ‚‚ to decimal

1
Bit positions (right to left): 128, 64, 32, 16, 8, 4, 2, 1
2
Binary digits: 1, 0, 1, 1, 0, 1, 0, 0
3
Multiply: (1ร—128)+(0ร—64)+(1ร—32)+(1ร—16)+(0ร—8)+(1ร—4)+(0ร—2)+(0ร—1)
4
Add: 128 + 0 + 32 + 16 + 0 + 4 + 0 + 0 = 180

Answer: 10110100โ‚‚ = 180โ‚โ‚€

Worked Example 3 โ€” Convert 11111111โ‚‚ to decimal

1
All 8 bits are 1, so we add all position values
2
128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255

Answer: 11111111โ‚‚ = 255โ‚โ‚€ โ€” this is the maximum value of one byte

Converting Decimal to Binary

To convert a decimal number to binary, use the repeated division by 2 method. Divide the number by 2, write down the remainder (0 or 1), then divide the quotient by 2 again. Repeat until the quotient reaches 0. The binary number is the remainders read from bottom to top.

Worked Example 4 โ€” Convert 25โ‚โ‚€ to binary

1
25 รท 2 = 12 remainder 1
2
12 รท 2 = 6 remainder 0
3
6 รท 2 = 3 remainder 0
4
3 รท 2 = 1 remainder 1
5
1 รท 2 = 0 remainder 1 โ† stop here (quotient = 0)
6
Read remainders from bottom to top: 1, 1, 0, 0, 1

Answer: 25โ‚โ‚€ = 11001โ‚‚

Verify: (1ร—16)+(1ร—8)+(0ร—4)+(0ร—2)+(1ร—1) = 16+8+1 = 25 โœ“

Worked Example 5 โ€” Convert 200โ‚โ‚€ to binary

1
200 รท 2 = 100 r 0
2
100 รท 2 = 50 r 0
3
50 รท 2 = 25 r 0
4
25 รท 2 = 12 r 1
5
12 รท 2 = 6 r 0
6
6 รท 2 = 3 r 0
7
3 รท 2 = 1 r 1
8
1 รท 2 = 0 r 1 โ† stop
9
Read bottom to top: 11001000

Answer: 200โ‚โ‚€ = 11001000โ‚‚

Binary Addition

Binary addition follows the same rules as decimal addition, but with only two digits. The rules are:

Worked Example 6 โ€” Add 1011โ‚‚ + 0110โ‚‚

1
Rightmost column: 1 + 0 = 1. Write 1.
2
Next column: 1 + 1 = 10. Write 0, carry 1.
3
Next column: 0 + 1 + 1 (carry) = 10. Write 0, carry 1.
4
Next column: 1 + 0 + 1 (carry) = 10. Write 0, carry 1.
5
Final carry: write 1.

Answer: 1011โ‚‚ + 0110โ‚‚ = 10001โ‚‚ (= 11 + 6 = 17 โœ“)

Binary and Data Storage

Understanding binary helps you understand how computers measure and store data. The units of storage are all based on powers of 2:

UnitSymbolSizeApproximate Value
Bitb1 binary digit (0 or 1)โ€”
Nibbleโ€”4 bitsโ€”
ByteB8 bitsOne character (e.g. the letter A)
KilobyteKB1,024 bytesA short text message
MegabyteMB1,024 KBA digital photograph
GigabyteGB1,024 MBAbout 250 songs
TerabyteTB1,024 GBA large hard drive

Note that storage units use powers of 2 (1,024 = 2ยนโฐ) rather than powers of 10 (1,000). This is a common source of confusion โ€” a hard drive manufacturer may advertise a "1 TB" drive using 1,000,000,000,000 bytes, but your operating system will show slightly less because it uses the binary definition (1,099,511,627,776 bytes = 1 TB).

Binary and ASCII โ€” How Text Is Stored

Every letter, number and symbol you type on a keyboard is stored in the computer as a binary number. The ASCII (American Standard Code for Information Interchange) system assigns a number to each character, which is then stored in binary.

For example: the letter A has ASCII code 65, which in binary is 01000001. The letter a (lowercase) has ASCII code 97, which in binary is 01100001. The digit 0 (the character, not the number) has ASCII code 48 = 00110000.

This means when you type the word "Hello" and save it in a file, the computer actually stores five bytes of binary data โ€” one byte per character โ€” each representing an ASCII code.

Common Mistakes to Avoid

KCSE Examination Tips

Binary number conversions appear regularly in KCSE Computer Studies Paper 1. Here is what to focus on:

๐ŸŽฎ Test Your Binary Knowledge

Practice binary-to-decimal conversion with instant feedback in our free interactive game.

Play Binary Explorer โ†’

Summary

Binary is the base-2 number system using only 0 and 1. Computers use binary because transistors have two stable states (on/off). Each bit position represents a power of 2 (from right: 1, 2, 4, 8, 16, 32, 64, 128). To convert binary to decimal, add the values of positions with a 1. To convert decimal to binary, repeatedly divide by 2 and read remainders upward. Eight bits make one byte, which is the basic unit of data storage and can represent numbers from 0 to 255.