Understanding Number Bases
A number base (or radix) is the number of unique digits, including zero, used to represent numbers in a positional numeral system. While we use Decimal (Base 10) in daily life, computers rely heavily on Binary (Base 2), Octal (Base 8), and Hexadecimal (Base 16).
Common Bases
- Decimal (Base 10): The standard system used by humans. Digits 0-9.
- Binary (Base 2): The fundamental language of computers. Uses only 0 and 1. Each digit represents a "bit".
- Octal (Base 8): Used in some computing systems (like Unix file permissions). Digits 0-7. Each digit represents exactly 3 bits.
- Hexadecimal (Base 16): Used to represent binary data in a more human-readable way. Uses digits 0-9 and letters A-F. Each digit represents 4 bits.
Conversion Logic
To convert between bases, we essentially perform repeated division (to convert down) or multiplication (to convert up).
- Bin -> Dec: Sum of $(digit \times 2^{position})$. E.g., $101 = (1\times4) + (0\times2) + (1\times1) = 5$.
- Dec -> Hex: Divide by 16 repeatedly, tracking remainders. The remainders (in reverse order) form the Hex number.
Common Hex Values
In web development, Hex is used for colors:
- Black: #000000
- White: #FFFFFF
- Red: #FF0000
- Green: #008000
- Blue: #0000FF
Frequently Asked Questions (FAQ)
Why are Hex letters uppercase?
Conventionally, hexadecimal letters (A-F) are written in uppercase to avoid ambiguity with lowercase words or variable names. However, `A` and `a` have the same numerical value.
How do I calculate Decimal from Binary?
Look at the digits from right to left. Multiply each digit by $2^0, 2^1, 2^2...$ respectively, and sum the results. For example, $1101_{binary} = 1\times8 + 1\times4 + 0\times2 + 1\times1 = 8+4+0+1 = 13_{decimal}$.