Binary numbers
How to write any whole number with only 0 and 1: place values that double, counting with carries, converting both ways, and why this suits a machine made of switches.
In 30 seconds
Binary is a way of writing numbers with two digits instead of ten. Each column is worth twice the one on its right: 1, 2, 4, 8, 16 and so on.
To read a binary number, add the place values of the columns that hold a 1. So 1101 is 8 + 4 + 1 = 13.
Computers use it because their parts are switches with two reliable states, on and off. One binary digit is a bit; eight bits make a byte, which can hold 256 different values.
Binary numbers, step by step
This lesson covers whole numbers from zero up. Negative numbers and fractions use extra conventions (two’s complement, floating point) built on the same bits.
- Step 1: Place values in base ten. Everyday numbers use ten digits. A digit’s position decides what it is worth: ones, tens, hundreds, each column ten times the one before. Binary keeps this system and changes only the ten.
- Step 2: Base two: columns double. Binary has only two digits, 0 and 1, so each column is worth twice the one on its right: 1, 2, 4, 8. A 1 means the column counts, a 0 means it is skipped. One binary digit is called a bit.
- Step 3: Counting in binary. Counting works as in decimal, but a column fills up after 1 instead of after 9. Adding one to a 1 resets it to 0 and carries into the next column, so 1 is followed by 10, 11 by 100, and 111 by 1000.
- Step 4: Binary to decimal. To read a binary number, write the place values above the bits, doubling from the right, and add up the columns that hold a 1. Here that is 32, 8, 4 and 1, which make 45.
- Step 5: Decimal to binary. To go the other way, divide by 2 over and over and note each remainder. The first remainder says whether the number is odd, so it is the ones bit; the last one is the leftmost bit. Read from the bottom up, 45 gives 101101.
- Step 6: Why computers use two. A computer is built from transistors acting as switches, and a switch has two clear states. A wire only has to be told apart as high or low, so a signal blurred by noise is still read correctly. Ten levels in the same range would sit too close together.
- Step 7: Bits and bytes. Bits are handled in groups of eight called bytes. Our 45 fits in one byte as 00101101; the zeros on the left add nothing. Eight bits make 256 different patterns, enough for the numbers 0 to 255, and every extra bit doubles the count.
Try it yourself
Learn this first
Nothing. This concept starts from scratch.
Learn next
- Logic gates (AND, OR, NOT, XOR)NOT, AND, OR and XOR as truth tables, and how NAND gates alone can build them all. Beginner
- Character encoding (ASCII, Unicode, UTF-8)How text becomes bytes, from ASCII's 128 characters to UTF-8, and why it sometimes garbles. Beginner
- How computer memory stores bitsHow SRAM, DRAM and flash cells each hold one bit, and how an address finds it. Intermediate
Spotted a mistake on this page?