Binary-to-decimal conversion is fundamental in computing, electronics and networking. Understanding how computers represent numbers in base 2 is essential for any developer, whether for network masks, bitwise operations or understanding the internal workings of a processor.
A binary number is expressed in base 2: each digit (bit) is 0 or 1, and its actual value depends on its position. The rightmost bit is worth 2⁰ = 1, the next is worth 2¹ = 2, then 2² = 4, 2³ = 8, etc. To convert to decimal, multiply each bit by its position value and add up the results.
📐 Formula
📊 Reference table
| Binary | Decimal | Detailed calculation |
|---|---|---|
| 0001 | 1 | 1×2⁰ = 1 |
| 0010 | 2 | 1×2¹ = 2 |
| 0100 | 4 | 1×2² = 4 |
| 0111 | 7 | 1×2² + 1×2¹ + 1×2⁰ = 4+2+1 |
| 1000 | 8 | 1×2³ = 8 |
| 1010 | 10 | 1×2³ + 1×2¹ = 8+2 |
| 1111 | 15 | 8+4+2+1 |
| 10000000 | 128 | 1×2⁷ |
| 11111111 | 255 | 128+64+32+16+8+4+2+1 |
💡 Practical examples
The other way round: convert a decimal number to binary
Converting a decimal number to binary is a basic skill in computing and digital electronics. It is necessary to understand Unix permissions (chmod 755 = 111 101 101), network addresses, bitwise operations and the internal representation of data.
The successive division by 2 method is the simplest for converting decimal to binary. Divide the number by 2 repeatedly, note the remainders (0 or 1) at each step, and read the remainders from bottom to top to get the binary representation. Alternatively, you can subtract successive powers of 2.
📐 Formula
📊 Reference table
| Decimal | Binary | Verification |
|---|---|---|
| 0 | 0 | — |
| 1 | 1 | 1 |
| 5 | 101 | 4+1 |
| 10 | 1010 | 8+2 |
| 15 | 1111 | 8+4+2+1 |
| 16 | 10000 | 16 |
| 42 | 101010 | 32+8+2 |
| 100 | 1100100 | 64+32+4 |
| 255 | 11111111 | 128+64+32+16+8+4+2+1 |