Beetwise

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.

  1. Bit 8 has the value 1. Add 2^8, which is 256.
  2. Bit 5 has the value 1. Add 2^5, which is 32.
  3. Bit 3 has the value 1. Add 2^3, which is 8.
  4. Bit 2 has the value 1. Add 2^2, which is 4.
  5. The total is 300.

The value of each bit position

The value of each bit position
BitPower of twoValue
02^01
12^12
22^24
32^38
42^416
52^532
62^664
72^7128
82^8256
92^9512
102^101024
112^112048
122^124096
132^138192
142^1416384
152^1532768

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 editor

Questions 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.