
Sequentia Explores: The Mathematics of Crypto
Part II: The Mathematician’s Toolkit
Lecture 9: Binary & Hexadecimal: Speaking the Language of Computers and Hashes
So far in our toolkit, we’ve collected abstract mathematical concepts: modular arithmetic, prime numbers, and Euclid’s algorithm. But computers don’t think in abstract concepts; they think in switches. On or off. Yes or no. One or zero. To bridge the gap between our mathematical ideas and their digital implementation, we need to learn to speak the native language of computers: binary.
Furthermore, to make the long, unwieldy strings of binary manageable for human eyes, we use a compact shorthand called hexadecimal. Today, we’ll demystify these number systems, which are fundamental to understanding everything from basic data storage to the structure of cryptographic hash values.
Base-10 (Decimal): The System We Know
First, let’s quickly reconsider the number system we use every day: base-10, or decimal. Why is it “base-10”? Because we have ten unique digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9). When we write a number like 257, we intuitively understand its meaning is based on powers of 10:
257 = (2 × 10^2) + (5 × 10^1) + (7 × 10^0)
257 = (2 × 100) + (5 × 10) + (7 × 1)
Each position in the number represents a different power of 10: the ones place, the tens place, the hundreds place, and so on.
Base-2 (Binary): The Language of On and Off
Computers don’t have ten fingers; they have billions of tiny electronic switches that can be in one of two states: on (represented by 1) or off (represented by 0). This is why they use base-2, or binary.
In binary, we only have two digits: 0 and 1. The positions of these digits don’t represent powers of 10, but rather powers of 2: the ones place, the twos place, the fours place, the eights place, and so on.
Let’s look at the binary number 1101:
To convert this to our familiar decimal system, we do the same positional math, but with powers of 2:
1101 (binary) = (1 × 2^3) + (1 × 2^2) + (0 × 2^1) + (1 × 2^0)
1101 (binary) = (1 × 8) + (1 × 4) + (0 × 2) + (1 × 1)
1101 (binary) = 8 + 4 + 0 + 1 = 13 (decimal)
So, 1101 in binary is the same as the number 13.
Each 0 or 1 is called a bit. A group of 8 bits is called a byte, which can represent any decimal number from 0 (00000000) to 255 (11111111). Everything your computer processes—text, images, this very lecture—is ultimately just a vast sequence of these ones and zeroes.
Base-16 (Hexadecimal): A Compact Shorthand for Binary
Binary is perfect for computers but terrible for humans. A number like 4,887,272 is 10010101011011111101000 in binary. It’s an unreadable mess! We need a more compact way to represent these long strings of bits.
This is where base-16, or hexadecimal (often just “hex”), comes in. Hexadecimal uses 16 unique digits. Since we only have 10 numeric digits, we borrow the first six letters of the alphabet:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Here, A represents the decimal value 10, B is 11, C is 12, D is 13, E is 14, and F is 15.
The magic of hexadecimal is its direct relationship with binary. A group of 4 bits (sometimes called a “nibble”) can represent any number from 0 (0000) to 15 (1111). This means a single hexadecimal digit can perfectly represent any possible combination of 4 bits!
- 0000Â (binary) =Â 0Â (hex)
- 1001Â (binary) =Â 9Â (hex)
- 1010Â (binary) =Â AÂ (hex) (decimal 10)
- 1111Â (binary) =Â FÂ (hex) (decimal 15)
Let’s convert our long binary number from before by grouping it into sets of 4 bits (starting from the right):
0100 1010 1011 0111 1110 1000 (we add leading zeroes to make a full group)
Now, we convert each 4-bit group into its hex equivalent:
- 0100Â = 4
- 1010Â = A
- 1011Â = B
- 0111Â = 7
- 1110Â = E
- 1000Â = 8
So, 10010101011011111101000 in binary becomes 4AB7E8 in hexadecimal. Much easier to read, write, and remember! You’ll often see hex values written with a 0x prefix, like 0x4AB7E8, to indicate that it’s a hexadecimal number.
Why Hexadecimal is Everywhere in Cryptography
When you see a cryptographic hash (a unique “fingerprint” of data, which we’ll cover soon), it’s almost always represented in hexadecimal. For example, a SHA-256 hash looks like this:
0x1A2B3C4D5E…
This isn’t a random string of letters and numbers. It’s a compact, human-readable representation of a very long binary number (256 bits, in the case of SHA-256). Each pair of hex characters represents one byte (8 bits) of the hash value.
Understanding hexadecimal allows us to:
- Represent large binary values concisely.
- Quickly convert back and forth to binary to understand the underlying data.
- Recognize the structure of digital artifacts like hash values, memory addresses, and color codes (#FFFFFF is hex for white).
While the deep mathematics of cryptography often operates on abstract numbers, the final output that we see and work with is almost always expressed in the practical, efficient language of hexadecimal. Learning to read binary and hex is like learning the alphabet and grammar of the computer’s native tongue.
In our next lecture, we’ll dive into our first historical cipher, the Caesar Cipher. We’ll use our knowledge of modular arithmetic and the concept of representing letters as numbers to see how one of the world’s oldest cryptographic puzzles works.