Binary, ASCII & RGB Explained: How Computers Turn Text and Color Into Numbers
A computer never actually stores a letter, a word, or a color. It only stores numbers, written in bits (0s and 1s). Whether one of those numbers gets displayed as the letter "C", printed as part of a colour swatch, or ignored as a control signal depends entirely on which program is reading it and what that program has been told to expect. Most explanations cover binary, ASCII, and RGB as three separate topics. Once you see them side by side, doing the same byte-to-hex conversion three different ways, the connection between them stops being three things to memorize and becomes one trick applied three times.
Bits and bytes: the only alphabet a computer has
A bit is a single binary digit, 0 or 1. A byte is a group of 8 bits treated as one unit — that's not a rough rule of thumb, it's the standard definition NIST's own computer security glossary uses: "a sequence of 8 bits." One byte can hold 2⁸ = 256 different values, which is exactly why you keep seeing the range 0–255 throughout this page.
Each bit in a byte has a place value, doubling from right to left, the same way each digit in a decimal number has a place value based on powers of 10:
| Bit position (left to right) | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| Place value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
To read a byte, add up the place values wherever there's a 1. Take 01000001: there's a 1 in the 64 column and a 1 in the 1 column, and every other bit is 0. So the value is 64 + 1 = 65. Keep that number in mind — it's about to show up twice more.
From byte to hex in one step: the nibble trick
Programmers rarely write bytes out in binary because 8 digits of 0s and 1s is hard to scan at a glance. Instead they split the byte into two 4-bit halves, called nibbles, and write each nibble as a single hexadecimal (base-16) digit, 0–9 then A–F for ten through fifteen. A nibble has exactly 2⁴ = 16 possible values, which is exactly the size of one hex digit — that's not a coincidence, it's why hex was chosen for this job.
Splitting 01000001 into nibbles gives 0100 and 0001. The first nibble, 0100, is 4. The second, 0001, is 1. Write them side by side and the byte becomes 0x41 in hex — matching the 65 you already calculated (4 × 16 + 1 = 65). Binary, decimal, and hex are three different scripts for writing down the exact same number.
Turning letters into numbers: ASCII
ASCII (American Standard Code for Information Interchange) is simply an agreed-upon list that says which number stands for which character: 65 means the capital letter "A", 66 means "B", and so on up through the alphabet, digits, and punctuation. The standard that formalized this for computer networks, RFC 20 (later elevated to Internet Standard STD 80), specifies that ASCII is a 7-bit code — using only values 0–127 — embedded inside an 8-bit byte whose extra, highest-order bit is set to 0.
Here's the word "CODE" run through the same conversion from the bits section above, letter by letter:
| Letter | ASCII decimal | Binary (8 bits) | Hex |
|---|---|---|---|
| C | 67 | 01000011 | 43 |
| O | 79 | 01001111 | 4F |
| D | 68 | 01000100 | 44 |
| E | 69 | 01000101 | 45 |
Check any row with the nibble trick: "O" is 79. Split its binary 01001111 into 0100 and 1111 — that's 4 and 15, and 15 in hex is F, giving 0x4F. Same method, same answer, every time.
Turning color into numbers: RGB and hex codes
A pixel's color is stored as three numbers — how much red, green, and blue light to mix — and each of those three numbers is, again, just one byte, so each channel runs from 0 to 255. The W3C's CSS Color Module specifies the familiar #RRGGBB web color format as exactly this: three bytes, each written as two hex digits, one pair per channel.
Take the color (255, 87, 51) — a bright orange-red. Convert each channel to hex using the same division method the nibble trick is shortcutting:
- 255: 255 ÷ 16 = 15 remainder 0, and 15 in hex is F — so 255 becomes
FF(the maximum a byte can hold). - 87: 87 ÷ 16 = 5 remainder 7 (5 × 16 = 80, and 87 − 80 = 7) — so 87 becomes
57. - 51: 51 ÷ 16 = 3 remainder 3 (3 × 16 = 48, and 51 − 48 = 3) — so 51 becomes
33.
Stack the three pairs together with a leading # and you get #FF5733 — a real, valid web color code for that orange-red. Because each channel is a full byte, three channels together give 256 × 256 × 256 = 16,777,216 possible colors, the "24-bit true color" figure you'll see quoted for most modern screens.
One byte, three meanings
The same number can be a letter, a color intensity, or nothing printable at all — it depends entirely on which rulebook the program applies to it. This table reuses the decimal-to-binary-to-hex method from every section above, applied to three specific byte values:
| Decimal | Binary | Hex | As ASCII text | As one RGB channel |
|---|---|---|---|---|
| 0 | 00000000 | 00 | NUL (a non-printable control code) | that color channel fully off |
| 65 | 01000001 | 41 | the letter "A" | a fairly dim shade of that channel (about 25% of full brightness) |
| 255 | 11111111 | FF | outside standard 7-bit ASCII entirely (bit 8 is set, and RFC 20's rule reserves that top bit) | that color channel at full brightness |
That last row is worth sitting with: 255 is a perfectly normal, maximum-brightness color value, but it can never be a plain ASCII character, because standard ASCII only defined the 128 values from 0 to 127. Anything from 128 to 255 needed a separate, later agreement (extended character sets, and eventually Unicode) to mean anything as text at all.
Quick reference
| Conversion | Method |
|---|---|
| Binary → decimal | Add the place value (128, 64, 32, 16, 8, 4, 2, 1) wherever there's a 1 |
| Binary → hex | Split into two 4-bit nibbles; write each nibble as one hex digit (0–9, A–F) |
| Decimal → hex | Divide by 16; the quotient is the first hex digit, the remainder is the second |
| Decimal → ASCII character | Look the number up in the ASCII table (65–90 = A–Z, 97–122 = a–z, 48–57 = 0–9) |
| Three decimals → hex color | Convert red, green, and blue each to a 2-digit hex pair, then join them after a # |
Once decimal, binary, and hex are three names for the same number rather than three separate systems to learn, ASCII and RGB stop being two unrelated facts to memorize — they're both just "here's what this particular byte means in this particular context." Try applying that to PassDrill's coding basics practice questions, which cover bits, bytes, ASCII, and how a single pixel's color is stored, among other beginner computing fundamentals.
Source: NIST Computer Security Resource Center Glossary, "byte" (a sequence of 8 bits); RFC 20 / STD 80, "ASCII format for Network Interchange" (IETF/RFC Editor) for the 7-bit ASCII range embedded in an 8-bit byte; W3C CSS Color Module Level 4 for the #RRGGBB hex color notation.