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 it
The value 300 in a 16-bit register. Select a bit to change it. Change the bit width or the signed mode to see the effect.
Name or expression
ID0
ASCII
·,
Binary
0b
0b0000000100101100
Hex
0x
0x012C
Decimal
300
Shift
Name or expression
ID0
Binary
0b
Hex
0x
Decimal
ASCII
·,
Shift
Sign
Bits
Endian
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
Worked example
Read the binary value 100101100 as a decimal value:
- Bit 8 has the value 1. Add 256.
- Bit 5 has the value 1. Add 32.
- Bit 3 has the value 1. Add 8.
- Bit 2 has the value 1. Add 4.
- The total is 300.
Where this 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.
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 tool
The full editor holds many values at the same time. It also evaluates expressions across them, and it reads live values from a serial port.
Open the full editorQuestions
- 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.