Binary, Decimal & Hex Converter

Your values

Mode
Input base

Use 0–9 and the letters A–Z for digit values 10 to 35. A minus sign, a point for fractions and the prefixes 0b, 0o and 0x are accepted; spaces and underscores are ignored.

Result

Binary (2)
Octal (8)
Decimal (10)
Hexadecimal (16)
Base 36 (36)

Two's complement

Bit width
Bit pattern (binary)
1111 1111
Bit pattern (hex)
FF
Read as signed
-1
Read as unsigned
255

A negative number is stored as 2 to the power of the bit width plus the number, so its top bit is 1.

About this tool

Computers store everything as binary digits, people read decimal, and programmers often write hexadecimal because one hex digit stands for exactly four bits. This converter translates a number between those systems and any other positional base up to 36, where the letters A to Z stand for the digit values 10 to 35. Use it to check homework on number systems, decode a hex color or memory address, read a byte as a signed value, or see why 0.1 cannot be stored exactly in binary.

How it works

Type a number and choose the base it is written in. The converter shows the same value in binary (base 2), octal (base 8), decimal (base 10) and hexadecimal (base 16), plus any other base you pick from 2 to 36. Each digit is multiplied by a power of the base and the results are added, as in the formula below; to go the other way, the number is divided by the target base again and again and the remainders are read from last to first.

Whole numbers are converted exactly at any length, well beyond the 2532^{53} limit of ordinary JavaScript numbers. Fractions work too: digits after the point that repeat forever are shown in parentheses. For whole numbers, the two's complement panel shows the 8-, 16-, 32- or 64-bit pattern and how the same bits read as signed and unsigned integers. Switch to Calculate for addition, subtraction, multiplication, whole-number division, AND, OR, XOR and bit shifts in binary, octal, decimal or hex.

N=∑i=0n−1di bi=dn−1bn−1+⋯+d1b+d0N=\sum_{i=0}^{n-1}d_i\,b^{i}=d_{n-1}b^{n-1}+\dots+d_1b+d_0

Example

Binary to decimal: 1011012=1×25+0×24+1×23+1×22+0×21+1×20=32+8+4+1=45101101_2=1\times2^5+0\times2^4+1\times2^3+1\times2^2+0\times2^1+1\times2^0=32+8+4+1=45.

Decimal to hex: divide 2024 by 16 again and again. 2024=16×126+82024=16\times126+8, 126=16×7+14126=16\times7+14 and 7=16×0+77=16\times0+7. Reading the remainders from last to first gives 7, E (14) and 8, so 2024 is 7E8 in hexadecimal.

Two's complement: in 8 bits, −5 is stored as 28−5=2512^8-5=251, which is 11111011 in binary or FB in hex.

Assumptions and limits

Inputs can have up to 256 digits. Fractions are expanded to at most 64 digits after the point; when the repeating block is longer, the result ends with an ellipsis. Hex output uses capital letters, and digit grouping is only for readability: copied values contain no spaces. Arithmetic works on whole numbers. Division drops the fraction and reports the remainder, rounding toward zero like C and JavaScript. AND, OR and XOR treat negative numbers as two's complement with unlimited sign extension, and the right shift is arithmetic.

Frequently asked questions

How do I convert binary to decimal?

Write the powers of 2 under the digits from right to left (1, 2, 4, 8, 16 and so on) and add the powers that sit under a 1. For 1101 that is 8+4+1=138+4+1=13. The converter does this for numbers of any length.

How do I convert hex to decimal?

Each hex digit is worth a power of 16, and A to F stand for 10 to 15. So 2F16=2×16+15=472F_{16}=2\times16+15=47 and FF16=255FF_{16}=255. Two hex digits always make one byte, which is why colors such as #FF8800 are written in hex.

How do I convert decimal to binary?

Divide by 2 again and again and write down the remainders, then read them from bottom to top. For 13 the remainders are 1, 0, 1 and 1, so 13 is 1101 in binary. For small numbers it is often quicker to subtract the largest power of 2 that fits, repeat, and write a 1 for each power you used.

What is two's complement?

It is how computers store negative integers. In n bits, a negative number x is stored as 2n+x2^n+x, so the top bit is 1 for every negative value. In 8 bits the range is −128 to 127, and 11111111 means −1 when read as signed but 255 when read as unsigned.

Why does 0.1 never end in binary?

A fraction ends in base b only if its denominator has no prime factors other than those of b. One tenth has the factor 5, which 2 does not have, so 0.1 becomes 0.00011‾20.0\overline{0011}_2 and repeats forever. That is why 0.1 + 0.2 is not exactly 0.3 in floating-point arithmetic.

Link with your values

Add these parameters to this page’s address to open it with the values filled in, for example to share a calculation or to link to it from an AI assistant. The result is calculated in the browser: the page HTML shows an example for the default values, and the tool sets the data-url-params attribute once the link’s values are applied.

ParameterValueIf omitted
modeModeone of: convert, calculatedefault convert
valueNumber to converttext in the tool's notation, see the examples; used with mode = convertrequired
from_baseInput basewhole number; allowed 2–36; used with mode = convertdefault 10
to_baseAlso show in base (2–36)whole number; allowed 2–36; used with mode = convertoptional
bit_widthBit widthone of: 8, 16, 32, 64; used with mode = convertdefault 8
operand_baseBase of both numbersone of: 2, 8, 10, 16; used with mode = calculatedefault 2
aFirst number (A)text in the tool's notation, see the examples; used with mode = calculaterequired
operationOperationone of: add, subtract, multiply, divide, and, or, xor, shl, shr; used with mode = calculatedefault add
bSecond number (B)text in the tool's notation, see the examples; used with mode = calculaterequired
group_digitsGroup digits (binary in fours, hex in pairs, octal and decimal in threes)true or falsedefault true

Examples

  • ?value=ff&from_base=16
  • ?value=zz&from_base=36&to_base=2
  • ?value=0.1&from_base=10&to_base=3&group_digits=false
  • ?a=1011&operation=xor&b=0110
  • ?mode=calculate&operand_base=16&a=ff&operation=multiply&b=10

Write decimals with a point. Encode a space as %20, + as %2B, # as %23 and & as %26.

Result elements: [data-result-block="base_number_converter"]