How binary numbers work
Binary uses two digits, 0 and 1.
Each bit position holds a power of two.
To read a binary value, add the powers of two of all the bits that have the value 1.
Try binary numbers in the bit editor
The value 300 in a 16-bit register. Edit the expression or select a bit to flip it.
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
300
value · 16 bits · unsigned
- binary
- 0b0000000100101100
Bit width
Binary numbers step by step
Read the binary value 100101100 as a decimal value: The steps follow the value above.
- Bit 8 has the value 1. Add 2^8, which is 256.
- Bit 5 has the value 1. Add 2^5, which is 32.
- Bit 3 has the value 1. Add 2^3, which is 8.
- Bit 2 has the value 1. Add 2^2, which is 4.
- The total is 300.
The value of each bit position
| Bit | Power of two | Value |
|---|---|---|
| 0 | 2^0 | 1 |
| 1 | 2^1 | 2 |
| 2 | 2^2 | 4 |
| 3 | 2^3 | 8 |
| 4 | 2^4 | 16 |
| 5 | 2^5 | 32 |
| 6 | 2^6 | 64 |
| 7 | 2^7 | 128 |
| 8 | 2^8 | 256 |
| 9 | 2^9 | 512 |
| 10 | 2^10 | 1024 |
| 11 | 2^11 | 2048 |
| 12 | 2^12 | 4096 |
| 13 | 2^13 | 8192 |
| 14 | 2^14 | 16384 |
| 15 | 2^15 | 32768 |
Where binary numbers is used
A processor holds all values as bits.
A hardware register packs many small fields into one value.
To read such a register, you must know which bit holds which field.
Binary numbers: points to note
- Bit numbers start at 0. Bit 0 is the lowest bit, not the first bit on the left.
- A bit width of 8 holds the values 0 to 255. A larger value needs more bits.
- The value 300 needs 9 bits. Beetwise then uses a bit width of 16, because hardware registers use 8, 16, 32 or 64 bits.
The full bit editor
The full editor holds many values, evaluates expressions across them, and reads live values from a serial port.
Open this value in the full editorQuestions about binary numbers
- What is a bit?
- A bit is one binary digit. A bit holds the value 0 or the value 1.
- What is the largest 8-bit value?
- The largest unsigned 8-bit value is 255. All eight bits have the value 1.
- Why do computers use binary?
- A circuit holds two states reliably: on and off. Two states map directly to 1 and 0.