Data Representation & Number Systems

the binary number system

The decimal numbers you grew up with use ten different digit symbols (0 through 9), and every time you run out of symbols you carry into the next column. Binary plays exactly the same game with only two symbols, 0 and 1. Imagine a row of light switches, each either off or on: that single off/on choice is one binary digit, and a row of switches spells out a number. Computers love this because a wire is easy to build with two clean states (a low voltage and a high voltage), whereas reliably telling ten different voltage levels apart would be fragile and error-prone.

In decimal each column is worth ten times the one to its right (ones, tens, hundreds, that is 10^0, 10^1, 10^2). In binary each column is worth two times the one to its right (1, 2, 4, 8, 16, that is 2^0, 2^1, 2^2, 2^3, 2^4). To read a binary number you add up the place values wherever there is a 1. For example 0b1011 means one 8 plus zero 4s plus one 2 plus one 1, which is 8 + 2 + 1 = 11 in decimal. That is the whole trick: same rules as ordinary arithmetic, just with two symbols and powers of two instead of ten symbols and powers of ten.

Binary is the bedrock of everything a computer does. Numbers, letters, colours, sounds, and machine instructions are all, at the bottom, just patterns of 0s and 1s held in switches called transistors. When people say a machine is digital, this base-two encoding is what they mean. A common confusion: binary is not some exotic kind of number that is different from the number eleven written as 11 in decimal; 0b1011 and 11 are the same quantity, written in two different notations, the way 'eleven' and 'XI' are.

The 4-bit pattern 0b1101 reads as 8 + 4 + 0 + 1 = 13 in decimal. Counting up in binary goes 0, 1, 10, 11, 100, 101, 110, 111 — which is just 0, 1, 2, 3, 4, 5, 6, 7.

Reading a binary pattern by adding place values, and counting from zero in base two.

Two is chosen for engineering reliability, not for mathematical magic: two well-separated voltage levels are easy to tell apart and resist noise. Any base would work in theory; base two is just the most robust to build.

Also called
base twobase-2基底二二進制