Definition
What a number base means
A number base tells you how many digit values a positional numbering system uses. Moving one place to the left multiplies that place’s weight by the base. Converting a number between bases changes its digits while preserving its value.
- Place weights
- Successive powers of the base
- Binary digits
- 0 and 1
- Hexadecimal digits
- 0–9 and A–F
Place value in any base
Every number system works the same way: each digit is worth the base raised to a power depending on its position. In decimal, 255 is 2 × 100 + 5 × 10 + 5 × 1. In binary the place values are 1, 2, 4, 8, 16 and so on, and in hexadecimal they are 1, 16, 256, 4096.
Computers use binary because each digit maps to an on-off switch. Programmers use hexadecimal and octal as shorthand, since four bits fit into one hex digit and three bits into one octal digit.
A worked example
Take 255. Repeated division by 2 gives eight ones: 11111111, which is 8 bits and one byte. Grouped in fours it is 1111 1111, and each group of four bits is one hex digit, F, so the hexadecimal value is FF. In octal the three-bit groups are 011 111 111 (padding on the left), which is 377. Reversing it: FF in hex is 15 × 16 + 15 = 255.
Where you will meet other bases
Web colours use hex: #FF8800 is red 255, green 136 and blue 0. IP addresses and subnet masks use binary and decimal. File permissions on Linux use octal, and programming languages use prefixes 0b, 0o and 0x for binary, octal and hex. Base 36, using digits and letters, is common in short URLs and IDs.
For colour codes in particular, the colour calculator shows hex, RGB and more. For other conversions, try the unit converter.
Two’s complement and signed numbers
Computers store negative whole numbers in two’s complement: invert all the bits and add one. In an 8-bit system, 5 is 00000101 and −5 is 11111011, which is 251 when read as an unsigned number. This calculator shows a plain minus sign instead, so the result of −5 is −101 in binary, not 11111011.
The number of bits sets the range: 8 bits holds 0 to 255 unsigned, or −128 to 127 signed; 16 bits holds 0 to 65,535; 32 bits holds up to 4,294,967,295. The bits and bytes lines in the result show how much room a value needs.
Step-by-step example
Convert decimal 255 to binary, hexadecimal and octal, then convert its hexadecimal form back to decimal.
| Step | Result |
|---|---|
| Binary | 11111111 |
| Hexadecimal | FF |
| Octal | 377 |
| Bits needed for the binary value | 8 bits |
| Hexadecimal FF in decimal | 255 |
Formulas used
value = dₙ × bⁿ + … + d₁ × b¹ + d₀ × b⁰
- dₙ
- digit in the highest place
- d₁
- digit one place left of the rightmost digit
- d₀
- rightmost digit
- b
- number base
- n
- highest place index
Example: Binary 1101 = 1×2³ + 1×2² + 0×2¹ + 1×2⁰ = 8 + 4 + 0 + 1 = 13.
Divide by the base repeatedly and keep the remainders;
read the remainders from last to first.
Example: 255 ÷ 16 = 15 r 15, so 255 = FF in hex (15 = F).
1 hex digit = 4 bits (a nibble)
2 hex digits = 8 bits = 1 byte
1 octal digit = 3 bits
Example: Binary 1111 1111 → hex F F → 255 decimal.
When the answer can mislead
- The same string of digits can mean a different value when read in a different base.
- Leading zeros can specify a field width even though they leave the value unchanged.
- For a signed binary field, determine its bit width and signed format before interpreting it.
Questions
How do I convert decimal to binary?
Divide the number by 2 repeatedly and write down the remainders, then read them from the last to the first. For 13: 13 ÷ 2 = 6 r 1, 6 ÷ 2 = 3 r 0, 3 ÷ 2 = 1 r 1, 1 ÷ 2 = 0 r 1. Reading upwards gives 1101. The calculator does it instantly for any size of number.
How do I convert binary to decimal?
Multiply each binary digit by 2 raised to its position, counting from 0 on the right, and add them. For 1101: 1×8 + 1×4 + 0×2 + 1×1 = 13. Select "Binary (2)" as the base the number is in and read the decimal result.
What is hexadecimal and why is it used?
Hexadecimal is base 16. It uses the digits 0–9 and the letters A–F (A = 10 … F = 15). One hex digit represents exactly four binary digits, so it is a compact way to write binary data. It is used for colour codes (like #FF8800), memory addresses and byte values.
What is octal?
Octal is base 8, using digits 0–7. Each octal digit is three bits. It is used in some computing contexts, most commonly Unix file permissions such as 755 and 644.
Why does the calculator say a digit is invalid?
Every base only allows digits smaller than the base: binary allows 0 and 1, octal 0–7, decimal 0–9 and hexadecimal 0–9 and A–F. If you type 2 in a binary number, or G in hex, the number is not valid in that base. Check that you selected the right base.
Can it handle very large numbers?
Yes. The calculator uses exact integer arithmetic, so there is no rounding, however many digits the number has (up to 200 characters). For example 2 to the power 64 is 18,446,744,073,709,551,616 in decimal and 10000000000000000 in hex. It only accepts whole numbers, not fractions.
Sources
Embed this calculator
Cite this calculator
Number Base Converter. CalculatorLab. https://calculatorlab.site/calculators/number-base-calculator/. Last updated . Accessed .