Binary Conversion Formulas
Convert numbers between binary, decimal, octal, and hexadecimal with step-by-step formulas.
Covers bit operations and two-complement notation basics.
The Formula
Binary to Decimal: dₙ×2ⁿ + dₙ₋₁×2ⁿ⁻¹ + ... + d₁×2¹ + d₀×2⁰
Every number system uses positional notation where each digit's value depends on its position. Binary uses base 2, decimal uses base 10, and hexadecimal uses base 16.
Variables
| Symbol | Meaning |
|---|---|
| d | Digit value at each position |
| base | Number system base (2 for binary, 10 for decimal, 16 for hex) |
| position | Position index (starting from 0 on the right) |
Example 1
Convert binary 11010110 to decimal
1×2⁷ + 1×2⁶ + 0×2⁵ + 1×2⁴ + 0×2³ + 1×2² + 1×2¹ + 0×2⁰
128 + 64 + 0 + 16 + 0 + 4 + 2 + 0
11010110₂ = 214₁₀
Example 2
Convert decimal 255 to binary and hexadecimal
255 ÷ 2 = 127 R1, 127 ÷ 2 = 63 R1, ... (all remainders are 1)
Binary: 11111111
Hex: F = 15 in decimal, and 255 = 15×16 + 15
255₁₀ = 11111111₂ = FF₁₆
When to Use It
Use binary conversion when:
- Working with low-level programming or embedded systems
- Reading or writing memory addresses and color codes
- Understanding how computers store and process numbers
- Debugging bitwise operations in code
Key Notes
- Hexadecimal is favored in programming because each hex digit maps exactly to 4 bits: FF = 1111 1111 = 255; this makes hex a compact, readable shorthand for binary in memory addresses, color codes (#FF5733), and CPU register values
- Negative integers in computers typically use two's complement, not sign-magnitude: −1 in 8-bit two's complement is 11111111 (unsigned 255), which is why signed integer overflow wraps from 127 to −128 and causes unexpected behavior when unchecked
- When converting decimal to binary by repeated division, read remainders from bottom to top — the last computed remainder is the most significant bit; reading top to bottom (a common error) gives the number in reverse
- Octal (base 8) persists in Unix file permissions: chmod 755 means rwxr-xr-x, where 7 = 111₂ (read+write+execute), 5 = 101₂ (read+execute) — each octal digit maps exactly to 3 bits, making it a convenient shorthand for permission triplets