Digital Logic Fundamentals
Senior 4 · ICT
Digital Logic Fundamentals
Lesson 1 of 5
25 min
On the front of the railway station in St. Gallen, Switzerland, a giant clock shows the time with nothing but lamps that are either on or off. There are no digits at all. Anyone who knows the binary number system can read it; everyone else sees a pattern of blue shapes.

Computers work the same way. Inside a processor, billions of transistors act as switches that are either on or off, and a wire is at either a high or a low voltage. Two states are easy to make, fast to switch and hard to confuse, so every number, letter, colour and sound in a computer is stored as a pattern of 0s and 1s. To understand the logic circuits in the rest of this unit, you first need to count the way they do.
Definition
Number system (base, radix): a way of writing numbers with a fixed set of digits, in which each position is worth a power of the base. The base is written as a subscript: , , , .
| System | Base | Digits |
|---|---|---|
| Binary | 2 | 0, 1 |
| Octal | 8 | 0 to 7 |
| Decimal | 10 | 0 to 9 |
| Hexadecimal (hex) | 16 | 0 to 9, then A = 10, B = 11, C = 12, D = 13, E = 14, F = 15 |
Bit (binary digit): one 0 or 1. Nibble: 4 bits. Byte: 8 bits.
In decimal, . Every base works the same way: a number with digits in base has the value
In binary each place is worth a power of 2, so the place values, from the right, are 1, 2, 4, 8, 16, 32, 64, 128. A binary number is the sum of the place values where there is a 1.
So . With bits there are different patterns, so bits can store the whole numbers from to : one byte holds 0 to 255.
Divide the number by 2 again and again, writing down each remainder, until the quotient is 0. The remainders read from the last to the first (bottom to top) are the binary digits.
| Division | Quotient | Remainder |
|---|---|---|
| 157 ÷ 2 | 78 | 1 (least significant bit) |
| 78 ÷ 2 | 39 | 0 |
| 39 ÷ 2 | 19 | 1 |
| 19 ÷ 2 | 9 | 1 |
| 9 ÷ 2 | 4 | 1 |
| 4 ÷ 2 | 2 | 0 |
| 2 ÷ 2 | 1 | 0 |
| 1 ÷ 2 | 0 | 1 (most significant bit) |
Reading upwards: , which matches the place-value diagram. The same method with 8 or 16 in place of 2 converts decimal to octal or hexadecimal.
Because and , every octal digit stands for exactly 3 bits and every hex digit for exactly 4 bits. Split the binary number into groups from the right, add zeros on the left of the last group if needed, and convert each group.
Check: and . To go back from hex or octal to binary, write each digit as 4 (or 3) bits. Hex is how programmers write binary compactly: a byte is always exactly two hex digits, from 00 to FF. The web colour #1E90FF is three bytes: red , green , blue .
Crash Course Computer Science #4: Representing Numbers and Letters with Binary. Watch how place value works in base 2, why 8 bits make a byte, and how letters are stored as numbers.
Worked example 1: read the station clock
In the photo, the hours row has 5 lamps, the minutes and seconds rows have 6. Writing lit as 1 and dark as 0, from left to right:
The time is 9:25:46. Why 5 lamps for hours? Hours run from 0 to 23, and 5 bits reach , while 4 bits reach only 15. Minutes and seconds run to 59, which needs 6 bits (up to 63).
Worked example 2: hexadecimal to decimal and binary
Convert to decimal and to binary.
Binary: each hex digit becomes 4 bits: 1 → 0001, F → 1111, 4 → 0100, so .
Check: .
Worked example 3: add in binary
The rules are , , (write 0, carry 1) and (write 1, carry 1). Add .
| 2⁶ | 2⁵ | 2⁴ | 2³ | 2² | 2¹ | 2⁰ | |
|---|---|---|---|---|---|---|---|
| Carry | 1 | 1 | 1 | 1 | 1 | 1 | |
| First | 1 | 0 | 1 | 1 | 0 | 1 | |
| Second | 0 | 1 | 1 | 0 | 1 | 1 | |
| Sum | 1 | 0 | 0 | 1 | 0 | 0 | 0 |
Result: . Check in decimal: . In lesson 3 you will build a circuit that adds two bits.
Press Run. Python writes binary with the prefix 0b, octal with 0o and hex with 0x, so the first line prints 0b10011101 0o235 0x9d. int(text, base) converts the other way. Use it to check your answers to the practice questions, after you have worked them by hand.
Warning
Read the remainders upwards. The first remainder is the least significant bit (the rightmost). Writing them top to bottom reverses the number.
Group from the right. grouped in threes from the left gives 100 111 01, which is wrong. Always start at the rightmost bit, and pad the leftmost group with zeros.
Tip
Learn two lists by heart. The powers of 2 (1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024) and the 16 nibbles (0000 = 0 up to 1111 = F). With them, most conversions take seconds.
Practice
#C8C8C8. Find the decimal value of each component and explain why the colour is a grey.Key points
Sources and credits
bin(), oct(), hex() and int(): Built-in Functions, Python documentation, Python Software Foundation (linked for reference).This lesson adapts CC BY-SA material and is shared under CC BY-SA 4.0.
# Check your conversions (you will learn Python in Unit 4).
print(bin(157), oct(157), hex(157)) # decimal to binary, octal, hex
print(int("10011101", 2)) # binary to decimal
print(int("1F4", 16)) # hex to decimal
print(bin(0b101101 + 0b011011)) # binary additionQuick check