Binary and hex — study guide
The concept's fragments, read in order.
Everything is bits
Underneath every number, every line of text, every image and sound a computer holds, there is only one kind of thing: a bit, a slot that is either on or off. There is no second, richer layer hiding below it. A machine that can store and flip billions of two-state switches is the whole of the hardware, and everything else is a convention for reading meaning into patterns of those switches.
The trick is that the same pattern of bits means whatever we agree it means. The eight bits 01000001 are the number sixty-five, or the letter A, or one slice of a color, depending only on which rulebook is reading them. Nothing in the bits themselves says which — the interpretation lives in the program, not the storage.
So learning how data is stored is really learning a small set of these rulebooks: how to count in twos, how to pack bits into bytes, how to write those bytes compactly in hexadecimal, and how numbers stand in for text. None of it is deep, but all of it is load-bearing — it is the floor every other idea in computing stands on.
Counting with two symbols
Decimal has ten symbols, 0 through 9, and when you run out you carry into a new column worth ten times the last. Binary plays exactly the same game with only two symbols, 0 and 1, so each column is worth twice the one to its right instead of ten times. Those column values, read from the right, go 1, 2, 4, 8, 16, and on up, doubling every step.
Reading a binary number is just adding up the columns that hold a 1. The eight bits 01001101 have ones in the columns worth 64, 8, 4, and 1, and 64 + 8 + 4 + 1 is 77 — that pattern is how a computer stores the number seventy-seven. It works like the wheels of a car's odometer, where each wheel stands for a fixed amount and the digit showing on it says how many of that amount to count, where each wheel carries a fixed weight and the digit sitting in it says how many of that weight to count.
That is the entire mechanism. Every whole number a computer holds is a sum of doubling place values, and counting up in binary is nothing more exotic than 0, 1, then carry — 10, 11, carry again — 100. The columns do all the work.
Bits grouped into bytes
A single bit is too small to be useful on its own, so computers deal in fixed bundles. The standard bundle is the byte: eight bits, handled as one unit. Eight bits give 256 different patterns, from 00000000 to 11111111, so a byte holds a whole number from 0 to 255 — the all-ones pattern 11111111 being exactly 255. That range, 0 to 255, turns up constantly once you know to look for it.
Eight is the near-universal size of a byte, settled long enough ago to be written into the standards, and it is the grain almost everything else is measured in. Memory, file sizes, and network transfers are all counted in bytes, not loose bits, because the byte is the smallest chunk the hardware conveniently addresses.
Half a byte — four bits — comes up often enough to have earned its own name, the nibble. A nibble holds a whole number from 0 to 15, and the reason it matters is not arithmetic but notation: four bits are precisely what one hexadecimal digit can capture, which is what makes hex such a tidy way to write bytes down.
Hex — one digit per nibble
Binary is honest but exhausting to read: 01001101 is easy to miscount and tedious to copy. Hexadecimal fixes this by counting in sixteens instead of twos, using sixteen symbols — 0 through 9, then a through f for the values ten through fifteen. Sixteen is 2 to the fourth power, and that is the whole reason hex is convenient: one hex digit covers exactly four bits, a nibble, with no remainder.
Because a byte is two nibbles, a byte is always exactly two hex digits. Split 01001101 down the middle into 0100 and 1101; the first nibble is 4, the second is 13, which is written d, so the byte is 4d in hex. The translation runs four bits at a time and never needs carrying between the halves, because each nibble maps to its hex digit by a fixed, tiny table you can hold in your head.
That two-digits-per-byte tidiness is why hex, not binary, is what you actually see written down. A color, a memory address, a raw byte dumped for debugging — all of them are shown in hex precisely because every byte becomes a clean pair of characters.
Storing negative numbers
Bits are just on and off, so a byte has no minus sign to spend. To store negative numbers, computers reinterpret the same eight bits under a scheme called two's complement: the top bit keeps its place value, but that value counts as negative. In a byte the top column is worth 128, so under this scheme it is worth minus 128, and the other seven columns stay positive. An 8-bit byte then covers -128 up to 127.
To find the bit pattern for a negative number, you take the positive version, flip every bit from 0 to 1 and 1 to 0, and add one. The payoff is that ordinary binary addition just works across the sign: add the pattern for a number and the pattern for its negative and they sum to zero, with the carry falling off the top and being ignored. No special subtraction hardware is needed.
The scheme wraps, which is the one surprise. Counting up from 127 does not reach 128; it rolls over to -128, like a clock face, where counting past the highest hour rolls straight back around instead of going higher. That wraparound is exactly why a counter left running can suddenly flip from a large positive number to a large negative one — a real bug with a tidy explanation once you can see the top bit's negative weight.
Text is numbers too
Letters are not a different kind of data — they are numbers with a lookup table agreed on in advance. The oldest such table still in daily use is ASCII, which assigns a number from 0 to 127 to each of 128 characters: the letters, the digits, punctuation, and a handful of control codes. Uppercase A is 65, which is 01000001 in a byte, and the rest of the alphabet follows in order from there. It works like a shared codebook that both sides agree on, turning each symbol into a number and back again, a shared list that turns each symbol into a number and back.
ASCII's 128 slots only cover unaccented English, so modern text uses Unicode, which numbers well over a hundred thousand characters from every writing system and emoji. The common way to store those numbers is UTF-8, which encodes each character in 1 to 4 bytes: a plain ASCII character still fits in a single byte with the same value it always had, while rarer characters spend two, three, or four. Old ASCII text is therefore already valid UTF-8, which is much of why the scheme won.
The consequence worth keeping is that there is no such thing as raw text. Every string is bytes plus an encoding, and reading bytes with the wrong table is exactly what produces the garbled characters you see when a file's encoding is guessed wrong.
Where you'll meet hex
Once you can read a byte as two hex digits, hexadecimal stops being an abstraction and starts appearing everywhere you build. A web color like #4d9c3c is three bytes — red, green, blue — each a channel from 0 to 255 written as its two-digit pair, so 4d is a medium red and ff would be the channel turned all the way up. The same 0 to 255 range from a single byte, dressed in hex.
You will hit it again the moment you look at anything low-level. Memory addresses are shown in hex because a long address collapses into a short, byte-aligned string. A raw dump of a file or a network packet is printed as columns of hex bytes, because that is the only view that shows the actual stored bytes without an encoding getting in the way. Even a MAC address on your home network is just six bytes written in hex.
That is why this floor is load-bearing. Wiring a game server's protocol, reading a device register on a small robot, or debugging why a byte came out wrong on a home lab box all put you face to face with raw bytes, and every one of them is far less mysterious when ff reads instantly as 255 and a bit pattern reads as a number.