passdrill

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)12345678
Place value1286432168421

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:

LetterASCII decimalBinary (8 bits)Hex
C670100001143
O79010011114F
D680100010044
E690100010145

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:

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:

DecimalBinaryHexAs ASCII textAs one RGB channel
00000000000NUL (a non-printable control code)that color channel fully off
650100000141the letter "A"a fairly dim shade of that channel (about 25% of full brightness)
25511111111FFoutside 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

ConversionMethod
Binary → decimalAdd the place value (128, 64, 32, 16, 8, 4, 2, 1) wherever there's a 1
Binary → hexSplit into two 4-bit nibbles; write each nibble as one hex digit (0–9, A–F)
Decimal → hexDivide by 16; the quotient is the first hex digit, the remainder is the second
Decimal → ASCII characterLook the number up in the ASCII table (65–90 = A–Z, 97–122 = a–z, 48–57 = 0–9)
Three decimals → hex colorConvert 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.

Drill Coding & Computers practice questions →