Number Conversion
Binary, octal, decimal, hexadecimal, and shifts
Required Parameters
Waiting for input data...
Quick Answer
Hex maps to binary: each hex digit = 4 bits. FF = 11111111 = 255. Common values: 0xFF = 255, 0xFFFF = 65535, 0xFFFFFFFF = 4.29 billion. Convert binary to decimal by summing powers of 2. Two's complement: invert bits and add 1 for negative numbers.
Number Base Conversion Calculator
Convert numbers between binary, octal, decimal, and hexadecimal bases. Essential for embedded programming and digital design.
Base Systems
- Binary -- Base 2, used in digital logic
- Octal -- Base 8, Unix permissions
- Decimal -- Base 10, human-readable
- Hexadecimal -- Base 16, memory addresses and colors
Design Notes
Number base conversion is fundamental for embedded programming, memory addressing, register configuration, and protocol analysis. Hex is the standard for displaying binary data because it aligns perfectly with 4-bit nibble boundaries.
Common Mistakes
- 1
Mixing up 0x (hex prefix) with 0 (decimal) — 0x10 = 16, not 10.
- 2
Forgetting two's complement for signed integers — 0xFF is 255 unsigned but -1 signed (8-bit).
- 3
Using octal (0o prefix) accidentally in JavaScript by adding a leading zero to what should be a decimal number.
Knowledge Base
What is FF in hex?
FF in hexadecimal = 255 in decimal = 11111111 in binary. It represents the maximum value of an 8-bit unsigned byte. Each hex digit maps to exactly 4 binary bits (a nibble), so FF = 1111 1111. Common in programming: 0xFF is used for bitmasks, maximum byte values, and color codes (255, 255, 255 = white).
How do I convert binary to decimal?
Each binary digit represents a power of 2 from right to left: 2⁰=1, 2¹=2, 2²=4, 2³=8, 2⁴=16... Sum the values where the bit is 1. Example: 10110 = 16+0+4+2+0 = 22 decimal. For quick conversion: memorize powers of 2 up to 2¹⁰=1024.
How do I convert decimal to hexadecimal?
Repeatedly divide by 16 and note the remainders. Example: 255/16 = 15 remainder 15. 15/16 = 0 remainder 15. Remainders bottom-to-top: 15,15 = FF. Or group binary into 4-bit nibbles: 11111111 = 1111 1111 = F F = FF.
What is octal and where is it used?
Octal is base-8, using digits 0-7. Each octal digit maps to exactly 3 binary bits. It is used in Unix/Linux file permissions (755 = rwxr-xr-x) and some legacy computing systems. Octal was more common in early computing (DEC PDP-8) but has largely been replaced by hexadecimal.
Why do programmers use hexadecimal?
Hex maps perfectly to binary: each hex digit = 4 binary bits. This makes it easy to read memory addresses, color codes, MAC addresses, and register values. 0x1A3F is much more readable than 0001101000111111 (binary) or 6719 (decimal). Hex also aligns naturally with byte boundaries (2 hex digits = 1 byte).
What are common hex values I should memorize?
0x00 = 0, 0x0F = 15, 0x10 = 16, 0xFF = 255, 0x100 = 256, 0x3FF = 1023 (10-bit max), 0xFFF = 4095, 0xFFFF = 65535 (16-bit max), 0xFFFFFFFF = 4,294,967,295 (32-bit max). Color codes: #FF0000 = red, #00FF00 = green, #0000FF = blue.
How does two's complement work?
Two's complement represents signed integers. For positive numbers, it is the same as unsigned binary. For negative: invert all bits and add 1. Example (8-bit): -1 = invert 00000001 to get 11111110, add 1 = 11111111 = 0xFF. Range for 8 bits: -128 to +127. For 16 bits: -32768 to +32767.
What is BCD (Binary-Coded Decimal)?
BCD encodes each decimal digit separately in 4 binary bits. Example: 42 decimal = 0100 0010 in BCD (not 00101010 as in pure binary). BCD is used in digital clocks, calculators, and financial systems where exact decimal representation is required. It wastes some capacity but eliminates binary-to-decimal conversion errors.
What is the difference between signed and unsigned integers?
Unsigned: all bits represent magnitude. 8-bit range: 0 to 255. Signed (two's complement): the MSB indicates sign. 8-bit range: -128 to +127. For 32-bit: unsigned = 0 to 4.29 billion, signed = -2.15 billion to +2.15 billion. Choosing wrong type causes subtle overflow bugs.
How do bit shifts relate to multiplication?
Left shift by N bits = multiply by 2^N. Right shift by N = divide by 2^N (integer division). Example: 5 left-shifted by 3 = 5 × 8 = 40. This is fundamental to fast arithmetic in CPUs, DSPs, and embedded systems. Compilers often optimize multiplications by powers of 2 into shifts.