🍋
Menu
How-To Beginner 1 min read 282 words

Understanding and Using Number Base Conversions

Convert between decimal, binary, octal, and hexadecimal with practical programming applications.

Key Takeaways

  • A number base (radix) determines how many unique digits are used.
  • Computers process information as binary — sequences of 0s and 1s representing on/off states.
  • Hexadecimal provides a compact way to represent binary data — each hex digit maps to exactly 4 binary digits.
  • Octal's main modern use is Unix file permissions.
  • To convert decimal to any base: repeatedly divide by the base and collect remainders in reverse.

Number Systems Explained

A number base (radix) determines how many unique digits are used. Decimal (base 10) uses 0-9. Binary (base 2) uses 0-1. Octal (base 8) uses 0-7. Hexadecimal (base 16) uses 0-9 and A-F. Each system exists because it's useful in specific contexts — binary for hardware, hex for compact binary representation, octal for Unix permissions.

Binary: The Hardware Language

Computers process information as binary — sequences of 0s and 1s representing on/off states. Understanding binary is essential for bit manipulation, network masks, and low-level programming. The binary number 10110 equals 22 in decimal: (1×16) + (0×8) + (1×4) + (1×2) + (0×1). Each position represents a power of 2.

Hexadecimal: Compact Binary

Hexadecimal provides a compact way to represent binary data — each hex digit maps to exactly 4 binary digits. The byte value 11111111 (binary) = FF (hex) = 255 (decimal). Hex is ubiquitous in color codes (#FF6B35), memory addresses (0x7FFF0000), and MAC addresses (AA:BB:CC:DD:EE:FF). It's easier to read and write than long binary strings.

Octal: Unix Permissions

Octal's main modern use is Unix file permissions. The permission 755 means owner=rwx (7=4+2+1), group=r-x (5=4+0+1), others=r-x (5=4+0+1). Each octal digit represents exactly 3 binary bits, mapping perfectly to the read-write-execute permission model.

Conversion Techniques

To convert decimal to any base: repeatedly divide by the base and collect remainders in reverse. To convert any base to decimal: multiply each digit by the base raised to its position power and sum. Between binary and hex: group binary digits in fours from right, convert each group. Between binary and octal: group in threes. Programming languages provide built-in functions: Python's bin(), oct(), hex(), and int() with base parameter.

Công cụ liên quan

Hướng dẫn liên quan