What this tool does
Software stores numbers in binary, programmers read hexadecimal, people count in decimal, and moving between the three is a daily task for developers and students. Every system runs on positional notation, where a digit counts for the base raised to its place: 1011 in binary is 1×2³ + 0×2² + 1×2¹ + 1×2⁰ = 11. This converter handles any base from 2 to 36 and prints the positional working for each digit.
How it works
Positional notation is the single idea behind every base. In decimal, 255 means 2 hundreds, 5 tens and 5 units, and the same number in other bases uses the other place values: 11111111 in binary is 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1, 377 in octal is 3×64 + 7×8 + 7, and FF in hexadecimal is 15×16 + 15. All four spellings are exactly 255, which is the check to run after any conversion.
Converting into decimal means multiplying each digit by the base raised to its position and adding, so hex 1F is 1×16 + 15 = 31 and binary 1010 is 8 + 2 = 10. Converting out of decimal means dividing repeatedly by the base and reading the remainders upwards: 42 divided by 16 leaves a remainder of 10, written as A, giving 2A in hex. Binary converts to octal and hexadecimal by grouping bits in threes and fours, because 2³ = 8 and 2⁴ = 16.
Digits run 0 through 9 and then A through Z, so any base up to 36 can be written without special characters and letters are read case-insensitively. Input like ff, FF and Ff all mean the same value in base 16, while a digit must always be smaller than its base, which is why 9 is invalid in octal. Everyday uses include colour codes such as #FF0000, memory addresses, bit masks, network addressing and ASCII values, where the letter A is 65 in decimal and 41 in hex.
Worked example
Converting decimal 255 into hex, octal and binary, plus two spot checks.
- 255 ÷ 16 = 15 remainder 15, and 15 = F, so 255 = FF hex
- 255 = 377 octal (3×64 + 7×8 + 7 = 192 + 56 + 7) and 11111111 binary
- 42 ÷ 16 = 2 remainder 10, and 10 = A, so 42 = 2A hex
- 1F hex = 1×16 + 15 = 31 decimal; 1010 binary = 8 + 2 = 10 decimal
255 is FF in hex, 377 in octal and 11111111 in binary; 42 is 2A hex, 1F hex is 31, and 1010 binary is 10.
Accuracy and limitations
- A digit must be smaller than the base, so letters beyond the base are rejected: Z works in base 36 but not in base 16, and 9 is invalid in base 8.
- Values beyond JavaScript's safe integer limit of 9,007,199,254,740,991 cannot be held exactly, so extremely large conversions may be approximate.
- Fractional values in a non-decimal base often repeat, so digits after the radix point are rounded to a fixed number of places.
Frequently asked questions
- How do you convert decimal to binary?
- Divide by 2 repeatedly and read the remainders from the last one to the first. For 42 you get 21 r 0, 10 r 1, 5 r 0, 2 r 1, 1 r 0 and 0 r 1, so 42 in binary is 101010. Reading the remainders upwards is the direction that people most often reverse by mistake.
- How do you convert hex to decimal?
- Multiply each digit by 16 raised to its position, then add the results. 1F hex is 1 × 16¹ + 15 × 16⁰, which is 16 + 15 = 31 decimal. Letters stand for values from A = 10 up to Z = 35.
- How do I convert octal to decimal?
- Multiply each digit by 8 raised to its position and add them together. 377 octal is 3 × 64 + 7 × 8 + 7, which is 192 + 56 + 7 = 255 decimal. The same positional rule works in every base, including base 10 itself.
- What is base 2 to base 10 conversion?
- It is binary to decimal: add up the place value of every 1 bit. 1011 in binary is 8 + 0 + 2 + 1 = 11 in decimal, because the four positions are worth 8, 4, 2 and 1 from left to right.
- How do you convert ASCII to hex?
- Convert the character to its decimal code first, then convert that number to hex, so uppercase A is ASCII 65 and 65 becomes 41 hex. This tool operates on numbers, so the character to code step, using a reference chart or lookup, comes before the base change.
- Why do programmers use hexadecimal instead of binary?
- One hex digit maps exactly onto four binary bits, so bytes stay readable: FF hex is 11111111 binary, a full 8-bit byte. Hex is also shorter than writing the same value in base 10 and case-insensitive, which is why colour codes and memory addresses are written in it.