Welcome to the World of Number Bases!

Ever wondered how a computer, which is essentially a collection of millions of tiny "on/off" switches, can display your favorite games, videos, and photos? It all comes down to how we represent data. In this chapter, we are going to explore Number Bases—the different "languages" of counting that computers use to make sense of the world.

Don't worry if you aren't a "math person" yet! We'll break this down step-by-step with simple tricks and clear examples. By the end of this, you'll be speaking "computer" (Binary and Hexadecimal) like a pro.


1. What is a Number Base?

A number base (or radix) is simply the number of digits available in a particular system of counting. It tells us how many different symbols we can use before we have to "carry over" to the next column.

Common Bases in Computer Science:

  • Decimal (Base 10): This is what humans use! We have ten digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9). Think of it as counting on your ten fingers.
  • Binary (Base 2): This is the computer's native language. It only has two digits: 0 and 1. Computers use this because their hardware is made of switches that are either Off (0) or On (1).
  • Hexadecimal (Base 16): This is a "shorthand" used by programmers. It has 16 digits: 0–9 and the letters A–F.

How to spot a base:

To avoid confusion, we use a subscript to show which base we are using.
Example: \(67_{10}\) is decimal, \(1011_{2}\) is binary, and \(AE_{16}\) is hexadecimal.

Quick Review: The base tells you how many symbols you have. Base 10 has ten symbols; Base 2 has two symbols.


2. Binary (Base 2): The Power of Two

In Binary, every column is worth twice as much as the one to its right. We call these place values. In decimal, we have units, tens, and hundreds. In binary, we have units, twos, fours, eights, and so on.

Binary Place Value Table (for 8 bits/1 byte):

\(128\) | \(64\) | \(32\) | \(16\) | \(8\) | \(4\) | \(2\) | \(1\)

Memory Trick: Start at 1 on the far right and just keep doubling as you move left!

Example: Converting \(1011_{2}\) to Decimal

1. Put the binary digits into your place value table:
(8s column: 1) | (4s column: 0) | (2s column: 1) | (1s column: 1)

2. Add up the values where there is a "1":
\(8 + 0 + 2 + 1 = 11_{10}\)

Did you know? The word "Bit" stands for Binary Digit!


3. Hexadecimal (Base 16): The Shorthand

Hexadecimal (or "Hex") is used because binary strings can get very long and confusing for humans to read. One hex digit can represent exactly four binary bits (a nibble).

The Hex Digits:

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

  • A = 10
  • B = 11
  • C = 12
  • D = 13
  • E = 14
  • F = 15

Analogy: If Binary is like spelling out every single letter of a word, Hex is like using a shorthand symbol or emoji to represent the whole word. It's much faster to write!

Key Takeaway: We use Hex because it's easier for humans to read and less prone to errors than long strings of 0s and 1s.


4. Converting Between Bases

This is a core skill for your exam! Let's break down the most common conversions.

A. Binary to Hexadecimal (The "Group of 4" Trick)

This is the easiest way to convert!
1. Split your binary number into groups of four, starting from the right.
2. Calculate the value of each group (0–15).
3. Turn those values into Hex digits.

Example: Convert \(11010110_{2}\) to Hex.
Group 1 (left): \(1101\) = \(8+4+0+1 = 13\) (which is D)
Group 2 (right): \(0110\) = \(0+4+2+0 = 6\) (which is 6)
Result: \(D6_{16}\)

B. Hexadecimal to Binary

Just do the "Group of 4" trick in reverse!
1. Take each Hex digit.
2. Convert it into a 4-bit binary number.
3. Squash them together.

Example: Convert \(2A_{16}\) to Binary.
\(2\) = \(0010\)
\(A (10)\) = \(1010\)
Result: \(00101010_{2}\)

C. Decimal to Binary (The "Subtraction" Method)

1. Look at your binary place values (\(128, 64, 32, 16, 8, 4, 2, 1\)).
2. Find the largest value that fits into your number.
3. Put a "1" in that column, subtract the value, and repeat with the remainder.

Example: Convert \(45_{10}\) to Binary.
Does 128 fit? No (0). Does 64 fit? No (0).
Does 32 fit? Yes (1). \(45 - 32 = 13\).
Does 16 fit? No (0).
Does 8 fit? Yes (1). \(13 - 8 = 5\).
Does 4 fit? Yes (1). \(5 - 4 = 1\).
Does 2 fit? No (0).
Does 1 fit? Yes (1). \(1 - 1 = 0\).
Result: \(00101101_{2}\)


5. Why bother with Hexadecimal?

You might be asked why we use Hex in Computer Science. Here are the three main reasons to remember:

1. Easy Conversion: It is very simple to convert between Binary and Hex (using the groups of 4).
2. Human Readable: It is much shorter and easier for humans to understand than long binary strings (e.g., color codes like \(#FF5733\)).
3. Less Error Prone: Because it’s shorter, programmers are less likely to make mistakes when typing it out.

Common Mistake to Avoid: When converting Decimal to Hex, don't forget that 10 is A, not "10". If you write \(106_{16}\) instead of \(A6_{16}\), you've changed the value entirely!


Quick Review Box:
  • Base 2 (Binary): Digits 0, 1. Power of 2 place values.
  • Base 10 (Decimal): Digits 0–9. Normal human counting.
  • Base 16 (Hex): Digits 0–9, A–F. Used as a shorthand for binary.
  • 1 Hex digit = 4 Bits. This is the "magic connection" between the two.

Don't worry if this seems tricky at first! Like any language, it just takes a little practice. Try converting your age into binary today!