Binary Counting

Binary counting is the systematic enumeration of values using only two symbols (0 and 1), forming the number representation system used by all digital computers.

Why This Matters

Binary is not an arbitrary choice for digital computers — it is the natural number system for circuits that operate in two states (voltage high or low, switch open or closed). Any other base would require circuits capable of distinguishing more than two stable states, which is much harder to build reliably.

Understanding binary counting is the entry point to all digital literacy. Before circuits, before gates, before processors, there is this: how to represent any number as a sequence of 0s and 1s, and how to count through those representations in order. Everything built on top of digital electronics rests on this foundation.

Binary is also genuinely simple — more regular and logical than decimal, which accumulated historical irregularities over centuries. Binary counting follows a perfect pattern that can be seen, understood, and internalized within an hour of study.

The Positional Number System

Both decimal and binary use positional notation: the value contributed by a digit depends on its position. In decimal, each position represents a power of 10. In binary, each position represents a power of 2.

Decimal number 365:

  • 3 × 10² = 300
  • 6 × 10¹ = 60
  • 5 × 10⁰ = 5
  • Total: 365

Binary number 101101101:

  • 1 × 2⁸ = 256
  • 0 × 2⁷ = 0
  • 1 × 2⁶ = 64
  • 1 × 2⁵ = 32
  • 0 × 2⁴ = 0
  • 1 × 2³ = 8
  • 1 × 2² = 4
  • 0 × 2¹ = 0
  • 1 × 2⁰ = 1
  • Total: 256+64+32+8+4+1 = 365

Powers of 2 to memorize: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536. These appear constantly in digital systems.

Counting Sequence and Bit Patterns

Binary counting follows a strict pattern. Each increment flips the rightmost (least significant) bit, and carries propagate left when a bit rolls from 1 back to 0.

0-bit nibble count (4 bits):

0000 = 0      1000 = 8
0001 = 1      1001 = 9
0010 = 2      1010 = 10
0011 = 3      1011 = 11
0100 = 4      1100 = 12
0101 = 5      1101 = 13
0110 = 6      1110 = 14
0111 = 7      1111 = 15

Observation: bit 0 (rightmost) alternates 0,1,0,1… every count. Bit 1 changes every 2 counts. Bit 2 changes every 4 counts. Bit N changes every 2^N counts. This doubling period is exactly what flip-flop counters exploit: chain T flip-flops so each one’s clock is driven by the previous one’s output, and you get a binary counter automatically.

With N bits: 2^N distinct states, counting from 0 to 2^N − 1.

  • 4 bits: 0–15 (16 states)
  • 8 bits: 0–255 (256 states)
  • 16 bits: 0–65,535 (65,536 states)
  • 32 bits: 0–4,294,967,295 (~4.3 billion states)

Hexadecimal Shorthand

Binary strings of more than 8 bits are tedious to read and write. Hexadecimal (base 16) provides a compact shorthand: each hex digit exactly represents 4 binary bits (one nibble).

Hex digits: 0–9, then A=10, B=11, C=12, D=13, E=14, F=15.

Conversion: group binary bits into groups of 4 from the right, replace each group with its hex digit.

Binary 1011 0110 = 0xB6 (B=1011, 6=0110) Binary 1100 1010 0011 1111 = 0xCA3F

Reverse: replace each hex digit with its 4-bit binary equivalent. 0xFF = 1111 1111 (all ones, decimal 255) 0x80 = 1000 0000 (MSB only, decimal 128) 0x0F = 0000 1111 (low nibble ones, decimal 15)

Hex is universally used for memory addresses, machine code, register values, and binary constants in programs. A programmer who cannot fluently convert between binary, hex, and decimal is seriously handicapped in low-level work.

Converting to Decimal

To convert binary to decimal: sum the positional values of all 1-bits.

Binary 0b10110010:

  • Bit 7: 0 → 0
  • Bit 6: 1 → 64
  • Bit 5: 1 → 32
  • Bit 4: 0 → 0
  • Bit 3: 1 → 8
  • Bit 2: 0 → 0
  • Bit 1: 1 → 2
  • Bit 0: 0 → 0
  • Total: 64+32+8+2 = 106

To convert decimal to binary: repeatedly divide by 2, recording remainders. The remainders (last to first) give the binary digits.

Decimal 106:

  • 106 ÷ 2 = 53 remainder 0 (bit 0)
  • 53 ÷ 2 = 26 remainder 1 (bit 1)
  • 26 ÷ 2 = 13 remainder 0 (bit 2)
  • 13 ÷ 2 = 6 remainder 1 (bit 3)
  • 6 ÷ 2 = 3 remainder 0 (bit 4)
  • 3 ÷ 2 = 1 remainder 1 (bit 5)
  • 1 ÷ 2 = 0 remainder 1 (bit 6)

Reading remainders bottom-up: 1101010 = 0b01101010 = 0x6A. Verify: 64+32+8+2=106. ✓

With practice, mental conversion between hex and decimal for common values (0xFF=255, 0x80=128, 0x40=64, 0x7F=127) becomes second nature, making low-level programming significantly easier.

Gray Code

Binary counting has a property that can cause problems in some hardware applications: when counting from 0111 to 1000, all four bits change simultaneously. If they don’t change at exactly the same instant (which they won’t in real circuits), intermediate incorrect states (0110, 0101, etc.) exist briefly.

Gray code solves this: each successive value differs in only one bit, eliminating transient incorrect states.

Gray code sequence:

Decimal  Binary  Gray
   0      000    000
   1      001    001
   2      010    011
   3      011    010
   4      100    110
   5      101    111
   6      110    101
   7      111    100

To convert binary B to Gray G: G[i] = B[i] XOR B[i+1] (MSB: G[n] = B[n]).

Gray codes appear in rotary encoders (mechanical shaft angle sensors), ADC designs, and any application where intermediate states during counting transitions would cause incorrect outputs.