
Written and maintained by the PhDino author · Last reviewed 21 September 2026 · Checked against 4 independent reference calculations · how PhDino checks its numbers
How many bits a number needs, how many of those bits are 1, and what that means for a parity check.
Computers store every number in binary — a sequence of 0s and 1s — and a fundamental question in digital design is how many bits are needed to represent a given range of values. A value's bit width is set by the highest number that range needs to hold, since each additional bit doubles the range of representable values.
Population count (the number of 1-bits in a binary number, sometimes called Hamming weight) shows up throughout computing — from error-detection codes to certain low-level bit-manipulation algorithms. Parity is the simplest application: counting whether the number of 1-bits is even or odd, then adding one extra bit specifically chosen so the total (including the parity bit) always comes out to a fixed parity — a classic, simple way to detect (though not correct) single-bit transmission errors.
Bits required = ⌊log₂(n)⌋ + 1 (for n > 0) Even-parity bit = (population count) mod 2
PhDino earns a commission on qualifying purchases made through this link, at no extra cost to you.
Code: The Hidden Language of Computer Hardware and Software by Charles Petzold — Builds from switches and logic gates up to a working computer, one clear step at a time. (Bookshop.org UK, UK delivery only)
→ The full PhDino bookshelf on Bookshop.org (UK delivery only)
