Number Systems: Binary, Decimal, Hexadecimal
Computers process all data as electrical signals, interpreted as 1s and 0s. While humans naturally calculate in Base-10 (Decimal/Denary), machines rely on Base-2 (Binary). Computer scientists use Base-16 (Hexadecimal) as a compact, human-friendly way to represent long binary strings.
Learning Objectives
- 11.1.1.1 Explain the differences between the binary, decimal and hexadecimal number systems
- 11.1.1.2 Convert numbers between the binary, decimal and hexadecimal number systems
- 11.1.1.3 Explain the advantages of using hexadecimal numbers in computer systems
- 11.1.1.4 Perform arithmetic operations of addition and multiplication with binary numbers
Video Explanation
Watch a visual walkthrough of Base conversions (Binary, Decimal, Hexadecimal) and Binary Arithmetic.
Conceptual Anchor
The Language of Machines and Humans
Imagine number bases as different languages expressing the same exact quantity.
Decimal is our native tongue (10 fingers = 10 digits).
Binary is the hardware's native tongue (switches: ON = 1, OFF = 0).
Hexadecimal is the "translator's shorthand" — a way for programmers to read and write binary quickly without getting lost in a sea of 0s and 1s.
Rules & Theory
Core Number Systems
| System | Base | Available Digits | Example |
|---|---|---|---|
| Decimal (Denary) | 10 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 | 25510 |
| Binary | 2 | 0, 1 | 111111112 |
| Hexadecimal | 16 | 0-9, then A (10), B (11), C (12), D (13), E (14), F (15) | FF16 |
Why use Hexadecimal?
- Definition: A Base-16 number system widely used in computing to represent binary data.
- Advantages:
- Shorter and more compact than binary (1 hex digit exactly represents 4 binary bits / a nibble).
- Easier for humans to read, write, and debug without making transcription errors.
- Faster conversion to and from binary compared to decimal.
- Where it is applied: MAC addresses (e.g., 00:1A:2B:3C:4D:5E), IPv6 addresses, HTML color codes (e.g., #FF0000 for red), memory dumps, and assembly language programming.
Conversions
- Binary to Decimal: Use the positional weights (128, 64, 32, 16, 8, 4, 2, 1). Multiply each binary digit by its column value and sum them up.
- Decimal to Binary: Use the "Divide by 2" method (keep track of remainders reading from bottom to top) or subtract the largest possible power of 2.
- Binary to Hexadecimal: Group the binary number into sets of 4 bits (nibbles) starting from the right. Convert each nibble to its hex equivalent (e.g., 1010 1111 = A F).
- Hexadecimal to Binary: Convert each hex digit directly into a 4-bit binary sequence.
# Example: Converting Hexadecimal 2A to Binary and Decimal
Hex: 2 A (10 in decimal)
Binary: 0010 1010
Combined Binary: 00101010
# Converting 00101010 to Decimal:
(0 * 128) + (0 * 64) + (1 * 32) + (0 * 16) + (1 * 8) + (0 * 4) + (1 * 2) + (0 * 1)
= 32 + 8 + 2
= 42 in DecimalBinary Arithmetic
When working directly with hardware or low-level programming, we must add and multiply using only 0s and 1s.
| Addition Rules | Multiplication Rules |
|---|---|
| 0 + 0 = 0 | 0 × 0 = 0 |
| 0 + 1 = 1 | 0 × 1 = 0 |
| 1 + 0 = 1 | 1 × 0 = 0 |
| 1 + 1 = 0 (with a carry of 1) | 1 × 1 = 1 |
| 1 + 1 + 1 = 1 (with a carry of 1) | Multiplication of larger numbers uses standard long multiplication (shift and add). |
# Binary Addition Example: 1011 + 0110
1011 (11 in decimal)
+ 0110 (6 in decimal)
------
10001 (17 in decimal)
# Note the carry operations bubbling to the left!Common Pitfalls
Hexadecimal is NOT executed by the CPU
A frequent misconception is that processors execute hexadecimal code. They do not. The CPU only processes pure binary. Hexadecimal is strictly a presentation format to make life easier for human programmers.
Tasks
List three practical computing applications where hexadecimal numbers are commonly used.
Explain why a computer scientist would prefer viewing a memory dump in hexadecimal rather than binary.
Convert the decimal number 156 into binary, and then convert that binary result into hexadecimal.
Perform the following binary addition: 1101101 + 101011. Show your carry bits.
Self-Check Quiz
Q1: How many bits are represented by exactly one hexadecimal digit?
Q2: What is the rule for adding 1 + 1 in binary?
Q3: Convert the hexadecimal value '1F' into decimal.