Binary Number Value
In one sentence: Binary uses only the digits 0 and 1, and this formula turns a row of those digits into the ordinary number they stand for.
Read it out loud: “N equals the sum, for every position i from 0 up to n minus 1, of bit b sub i times 2 to the power of i.”
What each symbol means
| Symbol | Meaning |
|---|---|
| The ordinary (decimal) number that the bits stand for. | |
| How many bits the number has. An 8-bit number has . | |
| The position of a bit, counted from the right and starting at 0. Position 0 is the rightmost bit. | |
| The bit at position . It is always either 0 or 1. | |
| The place value of position : 1, 2, 4, 8, 16 and so on. Each place is worth twice the place on its right. | |
| “Add up the terms for every position from 0 to ”: go through all the bits and total their values. |
What the formula is doing
In everyday life we count with ten digits, 0 to 9, so our system is called decimal. Computer memory has two easy states, off and on, so computers count with two digits, 0 and 1. That system is called binary. Each binary digit is called a bit, short for binary digit.
A digit’s place decides how much it is worth. In decimal the places are ones, tens and hundreds, and each place is ten times the one on its right. In binary each place is worth two times the place on its right, so the places are 1, 2, 4, 8, 16 and so on.
To find the value, look at each bit. If it is 1, add the place value under it. If it is 0, add nothing. The formula writes exactly that: is 0 or 1, and is the place value, so each term is either 0 or a place value, and the sum is the number.
The formula has this shape because every place is a power of two. With bits the largest value is , and counting starts at 0, so bits give different values in total.
An everyday picture
Think of a row of light switches on a wall. The first switch controls one bulb, the next controls two, then four, then eight. Turning a switch on adds its bulbs to the total. A binary number works the same way: every bit that is on adds its place value, and the total of the lit bulbs is the number.
Worked example: Reading the binary number 1011
The bits are , read from left to right. That is 4 bits, so . The place values from left to right are , , and .
- Write the place values from left to right: , , , .
- Pair each bit with its place: the 1 sits in the 8 place, the 0 in the 4 place, the 1 in the 2 place and the 1 in the 1 place.
- Multiply each bit by its place value and add: .
- Total: .
- A byte is 8 bits. Its places run from down to , and setting all eight bits to 1 gives the largest value, . Zero is the smallest, so one byte holds 256 different values.
Answer: The binary number is the ordinary number 11. One byte can hold the whole numbers from 0 to 255, which is 256 values in all.
The numbers in this example are recomputed by script every time the site is built.
Common mistakes
- Adding the bits without their place values, so becomes . Each bit must be multiplied by its power of 2 first.
- Using a digit larger than 1 in a binary number. Binary digits are only 0 or 1, so is not a binary number.
- Starting the positions at 1 instead of 0. The rightmost bit has position 0 and place value .
- Mixing up binary and decimal. The digits mean ten in binary and one thousand and ten in decimal. Write the base when it is unclear, as in .
Where you will meet it
- Computer memory and storage, where every bit is kept as one of two electrical states.
- IPv4 internet addresses, which are 32 bits long and are usually written as four decimal numbers from 0 to 255.
- Colors on a screen, where a red, green or blue channel is often stored as one 8-bit byte from 0 to 255.
- Machine code, where each CPU instruction is a pattern of bits that the processor reads as a number.
Questions people ask
Why do computers use binary and not decimal?
Electronic circuits can tell two states apart reliably: a voltage is high or low, and a switch is on or off. Ten different voltage levels are much harder to keep apart. Two states keep the hardware simple and dependable.
What is a byte?
A group of 8 bits. One byte can hold 256 different values, the whole numbers from 0 to 255.
How do I convert a decimal number to binary?
Divide by 2 again and again and write down each remainder. Read the remainders from the last one to the first. For example, 11 divided by 2 leaves remainders 1, 1, 0 and 1. Read backwards, they give .
Related formulas
- Binary Search Steps: Binary search finds an item in a sorted list by checking the middle and throwing away half, and this formula counts how many checks that takes at most.
- De Morgan's Laws: De Morgan’s laws say that a NOT in front of a group of AND or OR conditions flips the group: AND becomes OR, and OR becomes AND.
- Shannon Entropy: Shannon entropy is one number, in bits, that says how unpredictable a source is. The more predictable it is, the less space its messages need.