Binary and hex are other ways to write the same number. Why machines use binary, why hex is handy, converting by hand and reading octal file permissions.
📚 Units and notation: why there are so many · 3/12·⏱ 阅读约需 4分钟·信息更新 2026-10-01
📋 基本信息4
Key
A base is a way of writing a number, not the number itself
Binary
Electricity has two stable states, which suits machines
Hexadecimal
Four binary digits map exactly to one hex digit
Note
Without a prefix such as 0x or 0b, the base is ambiguous
Base ten comes from fingers
There is no mathematical reason we use base ten; it settled that way because we have ten fingers. A base is an agreement about when to carry to the next place, and the number itself is the same however it is written. 255, 0xFF and 0b11111111 are one number written three ways. Other bases have been used historically. Sixty minutes in an hour and 360 degrees in a circle are traces of base sixty, and counting in dozens is a trace of base twelve.
Why machines use binary
The states an electronic circuit can distinguish reliably are high voltage and low voltage. Distinguishing ten levels would be far more vulnerable to noise. Computers therefore express everything in two states, and that notation is binary. A bit is one place holding one of those two states. Eight bits make a byte, and a byte can hold 2 to the power 8, or 256, distinct values: 0 to 255.
Why hexadecimal is convenient
Binary runs to too many digits for people to read. Sixteen is two to the fourth power, so four binary digits map exactly onto one hexadecimal digit. Converting between them therefore needs no arithmetic, only splitting into groups of four. That is why colour codes and memory addresses are written in hexadecimal. Hexadecimal is also the standard notation wherever bytes must be listed, such as IPv6 addresses and device MAC addresses.
Binary 1111 = hex F = decimal 15
Eight binary digits = two hex digits = one byte
Hex uses A to F after 0 to 9
Octal splits into groups of three and is used for file permissions
Marking the base
Written as just 10, it could be ten in decimal or two in binary. Programming therefore marks hexadecimal with 0x and binary with 0b. Errors from mistaking the base of an unprefixed number are hard to find, so making the notation explicit is safer. Depending on the language, octal is marked with 0o or with a leading zero, and some environments read any number with a leading zero as octal, so take care: 010 may be read as 8 rather than 10.
Converting by hand
To convert decimal to another base, divide repeatedly by that base and read the remainders backwards. To convert back, multiply each digit by the base raised to its position and add. Memorising a few common values removes the need to calculate in most situations. For example, converting 13 to binary: 13 ÷ 2 = 6 remainder 1, 6 ÷ 2 = 3 remainder 0, 3 ÷ 2 = 1 remainder 1, 1 ÷ 2 = 0 remainder 1, and reading the remainders backwards gives 1101. Going back, 1101 is 8 + 4 + 0 + 1 = 13.
Reading octal file permissions
File permissions on Unix-like systems, such as 755 or 644, are octal. Each digit stands for three binary digits: whether read, write and execute permissions are on or off. Read is 4, write is 2 and execute is 1, and their sum forms one digit. The three digits are, from the left, the owner, the group and everyone else.
7 = 4 + 2 + 1 = read, write and execute
5 = 4 + 1 = read and execute
4 = read only
755 = everything for the owner, read and execute for others
How negative numbers and fractions are written
Computers usually store negative numbers using two's complement. With 8 bits, that means holding −128 to 127 instead of 0 to 255. So the same bit pattern 11111111 reads as 255 unsigned and as −1 signed. Fractions are trickier: decimal 0.1 is an endlessly repeating number in binary and cannot be stored exactly. That is why in many programming languages 0.1 plus 0.2 does not come out as exactly 0.3. Values that must be exact, such as money, are often handled as whole numbers instead.
Values worth memorising
Memorising a few powers of two makes base conversion and size calculation much faster. The fact that 2 to the 10th is 1024, close to 1000, is also the starting point for understanding data sizes.