Decimal to Binary Converter
Decimal to binary with each division by 2, padding to 8–64 bits, two’s complement and fractions.
To convert hex to decimal, multiply each hex digit by its power of 16 and add the results: .
1A3F (base 16) in base 10
1A3F in hexadecimal (base 16) is 6719 in decimal (base 10).
| Base | Name | Value |
|---|---|---|
| 2 | binary | 1101000111111 |
| 8 | octal | 15077 |
| 10 | decimal | 6719 |
| 16 | hexadecimal | 1A3F |
Expand in powers of 16
Each digit is multiplied by 16 raised to the power of its position: 0 for the last integer digit, then 1, 2, … to the left and −1, −2, … to the right of the point. Letters stand for values above 9: A = 10, F = 15.
Result
This converter shows that working for any input. It also converts decimal to hex, binary and octal, or between any bases from 2 to 36, with fractions and exact repeating digits.
Hex to decimal
Plain-text formula: (h_k…h_1h_0)_16 = h_k · 16^k + ⋯ + h_1 · 16 + h_0
Each hex digit is worth its value times a power of 16, counting the rightmost digit as power 0. Add the products to get the decimal value.
Positional notation in any base
Plain-text formula: (d_k…d_1d_0.d_(−1)d_(−2)…)_b = ∑_{i} d_i b^i
The same rule works in every base, and digits after the point take negative powers. This is how a number in any base is turned into its value. Roman numerals are not positional, so they need the Roman numeral converter instead.
Repeated division (decimal to hex or any base)
Plain-text formula: n = q_0b + r_0, q_0 = q_1b + r_1, … ⇒ n = (r_k…r_1r_0)_b
Divide by the new base until the quotient is 0. The remainders are the digits, and the first remainder is the last digit.
Repeated multiplication (fractional part)
Plain-text formula: f · b = d_(−1) + f_1, f_1 · b = d_(−2) + f_2, …
The whole-number part of each product is the next digit after the point. If a fractional part repeats, so do all the digits after it.
The main result is the converted number. For hex or binary input, the result panel also gives the signed value: the same digits read as a two’s complement integer at the narrowest of 8, 16, 32 or 64 bits that holds them. FF is 255 unsigned but −1 as a signed byte. Use the binary calculator for fixed word sizes, overflow and bitwise operations.
A fraction ends in base b exactly when its denominator, in lowest terms, has only prime factors of b. One tenth is , and 5 does not divide 2 or 16, so 0.1 has no finite binary or hex form. That is why 0.1 + 0.2 is not exactly 0.3 in most programming languages, which store numbers in binary.
Write down the place value of each position, starting from 1 on the right and multiplying by 16 each step left: 1, 16, 256, 4096 and so on. Replace any letters by their values (A = 10, B = 11, C = 12, D = 13, E = 14, F = 15). Multiply each digit by its place value and add the products.
For example, 2F = 2 × 16 + 15 = 47, and 1F4 = 1 × 256 + 15 × 16 + 4 = 500. To go from decimal to hex, divide by 16 repeatedly and read the remainders from the last to the first: 500 ÷ 16 = 31 r 4, 31 ÷ 16 = 1 r 15 (F), 1 ÷ 16 = 0 r 1, so 500 = 1F4.
| Position (from right) | Power of 16 | Place value |
|---|---|---|
| 1st | 16⁰ | 1 |
| 2nd | 16¹ | 16 |
| 3rd | 16² | 256 |
| 4th | 16³ | 4,096 |
| 5th | 16⁴ | 65,536 |
| 6th | 16⁵ | 1,048,576 |
| 7th | 16⁶ | 16,777,216 |
| 8th | 16⁷ | 268,435,456 |
The single hex digits 0 to F match the decimal numbers 0 to 15, and each is exactly four binary digits. Two hex digits make one byte, from 00 to FF (0 to 255). The rows below cover the digits and the two-digit values people look up most often.
A common trap: hex 10 is 16, not ten, and hex 20 is 32. Hex 100 is 256, so every extra hex digit multiplies the range by 16.
| Hex | Decimal | Binary |
|---|---|---|
| 0 | 0 | 0000 |
| 1 | 1 | 0001 |
| 2 | 2 | 0010 |
| 3 | 3 | 0011 |
| 4 | 4 | 0100 |
| 5 | 5 | 0101 |
| 6 | 6 | 0110 |
| 7 | 7 | 0111 |
| 8 | 8 | 1000 |
| 9 | 9 | 1001 |
| A | 10 | 1010 |
| B | 11 | 1011 |
| C | 12 | 1100 |
| D | 13 | 1101 |
| E | 14 | 1110 |
| F | 15 | 1111 |
| 10 | 16 | 0001 0000 |
| 16 | 22 | 0001 0110 |
| 20 | 32 | 0010 0000 |
| 32 | 50 | 0011 0010 |
| 40 | 64 | 0100 0000 |
| 64 | 100 | 0110 0100 |
| 7F | 127 | 0111 1111 |
| 80 | 128 | 1000 0000 |
| FF | 255 | 1111 1111 |
| 100 | 256 | 0001 0000 0000 |
| 3E8 | 1,000 | 0011 1110 1000 |
| FFFF | 65,535 | 1111 1111 1111 1111 |
To convert binary to decimal, add the place values (1, 2, 4, 8, 16, …) wherever the bit is 1: 1101 = 8 + 4 + 1 = 13. The binary to decimal converter shows that working bit by bit, with signed two’s complement values and binary fractions.
To convert binary to hexadecimal, group the bits in fours from the right and replace each group with one hex digit from the table above. 1111 1111 = FF, 1010 1010 = AA and 1 0000 0000 = 100. For octal, group in threes instead: 11 111 111 = 377. Hex to binary is the same process backward, four bits per digit.
A minus sign in front, such as −1F, simply means −31; the converter handles it by converting the size and keeping the sign. In programming, though, negative numbers are usually stored in two’s complement, where the same digits can mean two things. In 8 bits, FF is 255 unsigned and −1 signed; in 16 bits, 8000 is 32,768 unsigned and −32,768 signed.
To read a hex value as signed, check its top bit at the word size you care about. If the top bit is 1, subtract from the unsigned value, where w is the number of bits: FF₁₆ = 255, and 255 − 256 = −1. The result panel does this for you at 8, 16, 32 or 64 bits.
Most languages have a built-in base converter. In Python, int("1A3F", 16) returns 6719, and hex(6719) gives back "0x1a3f". In JavaScript, parseInt("1A3F", 16) returns 6719 and (6719).toString(16) returns "1a3f"; for values above use BigInt("0xFFFFFFFFFFFFFFFF"). In C, strtoul("1A3F", NULL, 16) does the same for unsigned values.
In Excel and Google Sheets, =HEX2DEC("1A3F") returns 6719. HEX2DEC accepts at most 10 hex digits and reads them as a signed 40-bit number, so =HEX2DEC("FFFFFFFFFF") is −1, not 1,099,511,627,775. Use this converter when you need longer values or the unsigned reading.
Reading remainders in the wrong order. When dividing by 16 or 2, the first remainder is the last digit. Writing them in the order found reverses the number.
Treating hex 10 as ten. It is 16. Hex numbers without letters, such as 20 or 99, still use powers of 16.
Confusing the letter O with zero, or I with one. Hex only uses A to F. Bases above 16 use more letters, but O and I are still digits there (O = 24, I = 18), so check the base.
Losing precision on very large values. Spreadsheet and JavaScript numbers are exact only up to , about 9 × 10¹⁵, so a 64-bit hex value such as FFFFFFFFFFFFFFFF can come back wrong. This converter uses exact integer arithmetic for up to 120 digits.
Write the hexadecimal number 1A3F in base 10.
Answer: 1A3F₁₆ = 6719₁₀. In binary it is 0001 1010 0011 1111, one group of four bits per hex digit.
Multiply each hex digit by 16 raised to its position, counting from 0 on the right, and add the results. Letters count as A = 10 to F = 15. For example 2F = 2 × 16 + 15 = 47.
FF is 255: F × 16 + F = 15 × 16 + 15. It is the largest two-digit hex number and the largest value of one unsigned byte. As a signed 8-bit number, FF is −1.
Divide by 16 repeatedly and read the remainders from the last to the first, writing 10 to 15 as A to F. For 255: 255 ÷ 16 = 15 r 15, then 15 ÷ 16 = 0 r 15, so 255 = FF.
It is a prefix that marks the number as hexadecimal, used in C, Python, JavaScript and most other languages. 0x1F means hex 1F, which is 31. You can paste numbers with the 0x prefix straight into the converter.
Divide by 2 repeatedly and read the remainders upward: 13 ÷ 2 = 6 r 1, 6 ÷ 2 = 3 r 0, 3 ÷ 2 = 1 r 1, 1 ÷ 2 = 0 r 1, so 13 = 1101. The decimal to binary converter shows those divisions for any number, with 8- to 64-bit padding, and the binary to decimal converter goes the other way.
Because 0.1 = 1/10 and 10 has the prime factor 5, which 2 does not share. The binary digits repeat forever: 0.1 = 0.0(0011)₂. In hex the same value is 0.1(9)₁₆, which also never ends.
Up to 120 digits, exactly. The converter uses whole-number arithmetic with no rounding, so 64-bit values such as FFFFFFFFFFFFFFFF = 18,446,744,073,709,551,615 come out exact, unlike in a spreadsheet.
Decimal to binary with each division by 2, padding to 8–64 bits, two’s complement and fractions.
Binary to decimal with each bit’s power of 2 and a running total, signed or unsigned, fractions included.
Binary addition, subtraction and bitwise operations with steps, at 8 to 64 bits, signed or unsigned.
a mod n with steps, negative numbers, power mod and modular inverses.
Decimals and repeating decimals to fractions in lowest terms, and fractions back to decimals, with steps.
Type or tap expressions with exact fractions, memory, variables, constants and complex mode.
Learn more: For base-n arithmetic and bitwise operations in the full calculator, read base-n and bitwise operations. Why 0.1 has no exact binary form: floating point and rounding.
Results are calculated in your browser with methods checked by automated tests, and are intended for learning and general use. For engineering, medical, financial, legal or safety-critical decisions, verify important values independently and follow the rounding rules your work requires. How accurate are these results?