digiwleeaLearn
Open the lab →

Binary numbers

Counting with two symbols

5 min read

Binary is the base-2 number system: every value is written with just two digits, 0 and 1, so it maps directly onto a wire that is off or on. Each column is worth twice the column to its right.

This is the first page of the Number & logic group, the math the rest of the course speaks. Nothing here needs a circuit yet; it is the language. By the end you will read a row of 0s and 1s the way you read a decimal number.
A single wire in this simulator carries just two values, 0 or 1 (you will meet two more, Z and X, in signals, but they are not numbers). With only two symbols to work with, a computer cannot count 0,1,2,...,9 the way you do on paper. It counts in base 2, called binary, where each digit is a single bit. (Want to poke at it first? The interactive binary guide lets you click bits and count up, watching the value change.)

Place value: the same idea you already use

Decimal is base 10: the number 375 means 3*100 + 7*10 + 5*1. Each column is worth ten times the one to its right, and the digit says how many of that column you have. Binary works exactly the same way, except each column is worth two times the one to its right: 1, 2, 4, 8, 16, 32, 64, 128, ..., doubling as you move left. The binary converter turns any number between binary, decimal, and hex.
1011 (binary) = 1*8 + 0*4 + 1*2 + 1*1 = 11 (decimal)
So to read a binary number, write the column value above each 1, then add those values up. The 0s contribute nothing. The rightmost bit (worth 1) is the least-significant bit (LSB); the leftmost is the most-significant bit (MSB).
Try it
Read the binary number 1101 as a decimal value. (Write the column worth above each bit, then add the columns that hold a 1.)

Counting up in binary

Counting works by the same carry rule as decimal: increment the rightmost digit, and when a digit would exceed its highest symbol, it rolls over to 0 and carries 1 into the next column. In decimal 9 rolls to 0 and carries; in binary the highest symbol is 1, so a 1 rolls to 0 and carries almost immediately. The first several counts:
decimalbinary
0000
1001
2010
3011
4100
5101
6110
7111
Three bits count from 0 to 7. Watch the rightmost bit flip every step, the middle bit every two steps, the left bit every four: each column toggles half as often as the one to its right.
That halving pattern is worth remembering: the LSB alternates 0,1,0,1,... every count, the next bit every two counts, the next every four. A counter circuit is literally hardware that produces this table, and a program counter walks it to step through instructions.

How many values fit in n bits

Each bit you add doubles the count of patterns, because the new bit can be 0 or 1 on top of every pattern you already had. So n bits give 2^n distinct values, from 0 up to 2^n - 1.
n bits represent 2^n values, from 0 to 2^n - 1
One bit gives 2 values (0,1); two bits give 4 (0..3); four bits give 16 (0..15); and eight bits give 2^8 = 256 values, 0 to 255. Four bits is common enough to have a name: a nibble. Eight bits is the famous byte, the unit this whole course works in.
Predict, then check
Before opening the figure below: what decimal value is the nibble 1010? Then set those four bits in the lab and read the bits back on the probes.
A 4-bit value (a nibble): set the four input bits b3-b0 (their column worths are 8, 4, 2, 1) and read them back on the probes. Open it in the lab, switch some bits on, and add up the columns to get the value. Eight of these side by side make a byte.
Binary is the notation every later page is written in: a bus is eight of these bits side by side, an adder does this counting in hardware, and a byte in memory is exactly these eight columns. Next, a shorthand that makes long binary numbers readable: hexadecimal.

Frequently asked

What is binary?

Binary is the base-2 number system: every value is written with just two digits, 0 and 1. It maps directly onto a wire that is off (0) or on (1), which is why computers use it. Each column is worth twice the column to its right (1, 2, 4, 8, 16, ...).

How do you convert binary to decimal?

Write the column value above each bit (1, 2, 4, 8, ... going right to left), then add up the column worths wherever there is a 1. The 0s contribute nothing. For example, 1011 is 8 + 0 + 2 + 1 = 11.

How many values can n bits represent?

n bits represent 2^n distinct values, from 0 up to 2^n - 1, because each bit you add doubles the count of patterns. So 4 bits give 16 values (0 to 15) and 8 bits give 256 values (0 to 255).

What is the difference between a nibble and a byte?

A nibble is 4 bits (16 possible values) and a byte is 8 bits (256 possible values), so a byte is two nibbles. The byte is the main unit this course works in, and one nibble is exactly one hexadecimal digit.

Every lesson here builds toward one thing: a working CPU, from the transistor up.

Open the free lab →
Found this useful? Share itShare on X