A Wall of 8 Switches
Imagine a control panel in a science lab with 8 identical switches in a row. Each switch has only two positions: up or down. Nothing in between — no "half up." If you wanted to use this panel to send a coded message to a friend in the next room, how many different messages could you send? Each switch independently contributes 2 possibilities (up or down), and there are 8 switches, so the total number of distinct switch patterns is 2 multiplied by itself 8 times: 2×2×2×2×2×2×2×2 = 256. That single fact — 8 two-state switches give you 256 possible patterns — is, almost word for word, how every byte of data inside your phone, your laptop, and the servers behind UPI and IRCTC actually works. A transistor inside a chip is electrically much closer to a light switch than to a dial: it is far more reliable to build hardware that reads "voltage present" or "voltage absent" than hardware that reliably distinguishes ten different voltage levels for the ten decimal digits. That reliability is the entire reason computers are built on a two-state (binary) system rather than the ten-state (decimal) system you grew up counting with.
This chapter has two jobs. First, to make you completely fluent in binary — reading it, writing it, and converting it to and from the decimal numbers you already know. Second, to introduce hexadecimal, a second number system that programmers use constantly, and to show you exactly why it exists: it is not a separate, unrelated system, it is a compact shorthand for binary, built so that humans don't have to stare at long strings of 1s and 0s.
Decimal Is a Place-Value System — You Already Know the Rules
Before binary makes sense, it helps to notice something you've used since Class 1 without ever stating it explicitly: the number 202 does not mean "two, zero, two." It means 2 hundreds + 0 tens + 2 ones. The digit 2 in the leftmost position is worth 100 times more than the digit 2 in the rightmost position, purely because of where it sits. This is called a place-value system, and decimal (base 10) uses powers of 10 for its place values: ...1000, 100, 10, 1, reading right to left as 10⁰, 10¹, 10², 10³. We use base 10 because humans have 10 fingers — it's a historical accident, not a mathematical necessity. Any whole number greater than 1 can serve as the "base" of a place-value system, as long as you're consistent about it. Binary uses base 2. Hexadecimal uses base 16. The rules of place value don't change — only the base, and therefore the value of each position, changes.
Binary: The Same Rules, Only Two Digits Allowed
In binary (base 2), the only digits that exist are 0 and 1 — there is no digit "2" in binary, just as there is no digit "12" in decimal. The place values are powers of 2 instead of powers of 10: reading right to left, the positions are worth 1, 2, 4, 8, 16, 32, 64, 128, and so on — each position worth exactly double the one before it. An 8-digit binary number (called a byte) therefore has place values:
Position: 128 64 32 16 8 4 2 1
Bit value: 1 1 0 0 1 0 1 0
To find the decimal value of this binary number, add up the place values wherever there is a 1, and ignore the positions with a 0:
128 + 64 + 8 + 2 = 202
So the binary number 11001010 equals decimal 202 — the exact number of switch patterns we discussed only when all 8 switches are considered together as one number, not as this specific pattern. Let's slow this down into a repeatable method, because you will use it constantly:
- Write out the place values above each bit, starting from 1 on the right and doubling as you move left (1, 2, 4, 8, 16, 32, 64, 128, 256, ...).
- For every bit that is 1, write down its place value.
- Add all those place values together. That sum is the decimal equivalent.
Try it on 10110: place values under a 5-bit number are 16, 8, 4, 2, 1. The bits are 1,0,1,1,0, so we take 16 + 4 + 2 = 22. Binary 10110 is decimal 22.
Common Misconception: Binary "10" Is Not "Ten"
This is the single most common error students make, and it's an easy trap because the symbols look familiar. In decimal, the digit string "10" means ten. In binary, the digit string "10" means: 1×2 + 0×1 = 2. Binary "10" is decimal two, not ten. Similarly, binary "100" is decimal four (1×4 + 0×2 + 0×1), not one hundred. The symbols "1" and "0" are just symbols — their value depends entirely on which number system you've agreed to interpret them in, exactly the way the symbol "7" means something different in a phone number, an age, and a page number, except here the entire counting system itself has changed. When you see a binary number, always mentally attach the phrase "in binary" or convert it before speaking it aloud as if it were decimal — reading 1010 as "one thousand ten" instead of "ten" (its decimal value) is a mistake that costs marks in every CBSE Computer Science exam that includes number-system conversions.
Converting Decimal to Binary: Repeated Division by 2
Reading binary into decimal is a one-way sum. Going the other way — turning a decimal number into binary — uses a different, equally mechanical method: divide repeatedly by 2, and collect the remainders. Let's convert 202 back into binary, to confirm it really does return 11001010.
202 ÷ 2 = 101 remainder 0
101 ÷ 2 = 50 remainder 1
50 ÷ 2 = 25 remainder 0
25 ÷ 2 = 12 remainder 1
12 ÷ 2 = 6 remainder 0
6 ÷ 2 = 3 remainder 0
3 ÷ 2 = 1 remainder 1
1 ÷ 2 = 0 remainder 1
Now read the remainders from bottom to top (this order matters — it's the most common place students lose marks): 1 1 0 0 1 0 1 0. That is 11001010 — exactly the binary number we started with in the previous section. Why does reading bottom-to-top work? Because the first remainder you compute (0, from 202÷2) tells you whether 202 is odd or even, which is precisely the value of the ones place (2⁰). The last remainder you compute, after dividing all the way down to 1, corresponds to the highest place value. Since you compute the lowest place value first but write numbers with the highest place value on the left, you must reverse the order of the remainders when you write the final answer.
Why Hexadecimal Exists
Binary is exactly how a processor actually stores and manipulates data — but it's miserable for a human to read, write, or debug. Consider a processor's memory address like 1101111010111100. Now try to spot a typo in it, or compare it to a second 16-bit number, or simply say it out loud without losing your place. Programmers needed a way to write down the same binary information more compactly, without changing what the data actually is. The trick they landed on is hexadecimal (base 16), and it isn't arbitrary — it works because 16 is a power of 2 (16 = 2⁴). This means exactly 4 binary digits (called a nibble) can represent exactly 1 hexadecimal digit, with no leftover values and no gaps. Grouping binary into chunks of 4 and relabeling each chunk with a single hex symbol shrinks a 16-character binary string down to a 4-character hex string — a 4x reduction in length, with zero loss of information, and a trivial, mechanical rule for converting back and forth.
The 16 Hexadecimal Digits
Base 10 has ten digit symbols (0–9). Base 2 has two (0–1). Base 16 needs sixteen distinct symbols, one for each value from zero through fifteen. But we've run out of familiar digit shapes after 9 — there's no single character in ordinary Hindu-Arabic numerals for "the value twelve" the way "7" represents seven. So hexadecimal reuses the digits 0–9 for the values zero through nine, and then borrows the letters A through F for the values ten through fifteen:
Decimal: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Binary: 0000 0001 0010 0011 0100 0101 0110 0111
1000 1001 1010 1011 1100 1101 1110 1111
Hex : 0 1 2 3 4 5 6 7 8 9 A B C D E F
So A = 10, B = 11, C = 12, D = 13, E = 14, F = 15. These letters are not variables and they don't stand for anything algebraic — they are fixed digit symbols, exactly as fixed in meaning as "7", just borrowed from the alphabet because we ran out of numerals. A number like 2D in hex is read digit by digit as "two, D" (or informally "two-dee"), never as a word that sounds like a decimal number.
Converting Binary to Hex: Group Into Nibbles
Because 4 binary bits map onto exactly 1 hex digit, converting binary to hex needs no arithmetic at all — just grouping and a lookup table. Take our earlier byte, 11001010:
Binary: 1100 1010
Group into nibbles, right to left first (though for a full byte the grouping is unambiguous):
Nibble 1: 1100 = 8+4 = 12 = C
Nibble 2: 1010 = 8+2 = 10 = A
Hex result: CA
So binary 11001010 = hex CA. As a sanity check, hex CA should equal decimal 202, the same number we computed directly from binary earlier. Hex place values are powers of 16 (16⁰=1, 16¹=16), so: C×16 + A×1 = 12×16 + 10×1 = 192 + 10 = 202. It matches exactly, which is exactly the point — hex CA and binary 11001010 are two different-looking labels for the identical value 202, related by a purely mechanical grouping rule, not by any new arithmetic.
When a binary number doesn't split evenly into groups of 4, pad it with leading zeros on the left until it does (padding on the left never changes a number's value, exactly the way writing "007" instead of "7" doesn't change seven). For example, convert binary 101101 to hex: it has 6 digits, so pad on the left to make 8: 00101101. Grouped: 0010 | 1101, which is 2 | D, giving hex 2D. Check by decimal: binary 101101 = 32+8+4+1 = 45, and hex 2D = 2×16 + 13 = 32+13 = 45. Matches.
Converting Hex to Decimal Directly
You don't need to pass through binary to convert hex to decimal — you can use hex place values (powers of 16) directly, exactly the way you used powers of 2 for binary. Take hex 3F: the place values for a 2-digit hex number are 16 and 1. So 3F = 3×16 + F×1 = 3×16 + 15×1 = 48 + 15 = 63. Try a 3-digit example, hex 1A4: place values are 256, 16, 1 (powers of 16: 16²=256, 16¹=16, 16⁰=1). So 1A4 = 1×256 + A×16 + 4×1 = 256 + 160 + 4 = 420.
Where You Actually Encounter Hex
Hexadecimal isn't a classroom curiosity — it shows up anywhere programmers need a compact, exact stand-in for binary data. The clearest everyday example is a web color code. When you set a background color in HTML/CSS as #FF5733, the browser is reading three bytes of binary data written in hex shorthand. Every color a screen displays is built from three channels — red, green, and blue light — and each channel's brightness is stored as one byte, meaning it can hold any value from 0 to 255 (2⁸ = 256 possible values, numbered 0 through 255). Written in hex, one byte always takes exactly 2 hex digits, ranging from 00 (binary 00000000, decimal 0 — channel fully off) to FF (binary 11111111, decimal 255 — channel at full brightness). So #FF5733 splits into three bytes: FF (red channel = 255, fully on), 57 (green channel = 5×16+7 = 87), and 33 (blue channel = 3×16+3 = 51) — producing a strong, bright orange-red. This is precisely why hex pairs are used for colors instead of, say, writing out three binary bytes or three decimal numbers: two hex digits give you the exact same 256 possible values as a full byte, in a fixed, predictable, compact width that's easy to type and easy to visually scan.
The same "2 hex digits = 1 byte" pattern is why hardware addresses (like a device's MAC address, written as something like 3C:5A:B4:7E:91:0F) and memory dumps in debugging tools are almost always shown in hex rather than binary or decimal — hex gives the shortest readable string that still lines up cleanly, byte for byte, with how the hardware actually stores the data.
Binary Addition: One Step Further
Once you're comfortable converting, it's worth seeing binary arithmetic itself, because CBSE exams sometimes ask you to add two binary numbers directly, without converting to decimal first. Binary addition follows the same "carry to the next column" logic as decimal addition — you just carry a lot more often, because a binary column overflows as soon as it reaches 2 (in decimal, a column overflows at 10). The four addition facts you need are: 0+0=0, 0+1=1, 1+0=1, and 1+1=10 (write 0, carry 1). Let's add 1010 (decimal 10) and 0110 (decimal 6), which should give us decimal 16:
1010
+ 0110
------
Column 1 (rightmost): 0+0 = 0
Column 2: 1+1 = 10 -> write 0, carry 1
Column 3: 0+1+carry(1) = 10 -> write 0, carry 1
Column 4: 1+0+carry(1) = 10 -> write 0, carry 1
Final carry out: 1
Result: 10000
Binary 10000 equals decimal 16 (place value 16, single 1 bit), confirming 10 + 6 = 16 was computed correctly using pure binary column addition, with no detour through decimal along the way.
Reading the Diagram
The figure below shows the complete pipeline for the byte 11001010: its place values, its two nibbles, and the hex digits those nibbles map to — all three representations of the exact same value, 202.
Practice: Test Yourself
Work these out on paper using the methods above before checking the answers that follow. Do not skip straight to the answers — the goal is to catch your own mistakes in the conversion steps, which is exactly what board exams will test.
- Convert binary 1101 to decimal.
- Convert decimal 39 to binary using repeated division by 2.
- Convert binary 11110000 to hex by grouping into nibbles.
- Convert hex 4B directly to decimal using powers of 16.
- Add binary 0111 and 0001 using column addition with carrying, and check your answer by converting both numbers to decimal first.
- A pixel's red channel is stored as hex 9E. What is this value in decimal, and is the channel closer to fully off or fully on (out of a maximum of 255)?
Answers: (1) 1101 = 8+4+1 = 13. (2) 39 → binary: 39÷2=19 r1, 19÷2=9 r1, 9÷2=4 r1, 4÷2=2 r0, 2÷2=1 r0, 1÷2=0 r1; reading bottom to top gives 100111. (3) 11110000 groups as 1111 | 0000 = F | 0 = F0. (4) 4B = 4×16 + 11×1 = 64+11 = 75. (5) 0111+0001: rightmost column 1+1=10 (write 0, carry 1), next column 1+0+carry1=10 (write 0, carry 1), next column 1+0+carry1=10 (write 0, carry 1), leftmost column 0+0+carry1=1 → result 1000; check: 7+1=8, and binary 1000=8. Matches. (6) 9E = 9×16 + 14×1 = 144+14 = 158, which is past the halfway point of 255, so the channel is closer to fully on than fully off, though not near maximum.
Summary
Decimal, binary, and hexadecimal are all place-value systems built on the same underlying idea — a digit's value depends on both the digit itself and its position — differing only in the base (10, 2, and 16 respectively) and therefore in which digit symbols are allowed and what each position is worth. Computers use binary at the hardware level because a transistor reliably distinguishes only two electrical states, not ten. Humans use hexadecimal as a compact, error-resistant shorthand for binary, made possible by the fact that 16 = 2⁴, so every group of exactly 4 bits maps onto exactly one of the sixteen hex symbols 0–9 and A–F with nothing left over. You now have three linked toolkits: reading binary and hex numbers into decimal using place values, converting decimal into binary or hex using repeated division, and converting directly between binary and hex using nibble grouping — the fastest of the three because it requires no arithmetic, only a lookup table you can now reconstruct from memory. Whether you're reading a color code, a memory address, or a networking value, that CA-equals-11001010-equals-202 relationship is the same mechanical fact playing out every time.