Binary, Decimal, Hex Converter

Convert whole numbers between binary, octal, decimal and hexadecimal exactly, or use the 64-bit programmer keypad for bitwise math and two's complement.

How we test our calculators
0
HEX0
DEC0
OCT0
BIN0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Or use the standard form below

Decimal (base 10) —
Binary (base 2) —
Octal (base 8) —
Hexadecimal (base 16) —
Size —

What is a binary, decimal, hex converter?

A binary, decimal and hex converter rewrites a whole number in another number base. Decimal (base 10) uses the digits 0 to 9, binary (base 2) uses 0 and 1, octal (base 8) uses 0 to 7, and hexadecimal (base 16) uses 0 to 9 plus A to F for the values 10 to 15. The number itself does not change, only the way it is written: 255, 1111 1111, 377 and FF are the same value.

This page has two tools. The programmer keypad at the top holds one 64-bit value. It lets you type in HEX, DEC, OCT or BIN mode, shows the value in all four bases at once, and has a row of 64 bits you can click to switch on or off. Its keys include +, −, ×, ÷, MOD, AND, OR, XOR, NOT and the shifts << and >>. It shows negative numbers in two's complement, the fixed-width signed format explained below.

The standard form below the keypad converts one number exactly, at any size. Type the Value, choose the Input base, and read the Decimal (base 10), Binary (base 2), Octal (base 8) and Hexadecimal (base 16) results, plus the Size in bits and bytes. It checks every digit against the base you chose, and it shows negative numbers with a minus sign rather than as two's complement. Both tools handle whole numbers only.

How it works

Place value

In any base b, each digit is multiplied by a power of b, counting from 0 at the right: value = dn × bn + … + d1 × b1 + d0 × b0. So binary 1011 = 8 + 0 + 2 + 1 = 11, and hex 1F4 = 1 × 256 + 15 × 16 + 4 = 500.

Converting from decimal: repeated division

Divide by the new base, write down the remainder, divide the quotient again, and stop at 0. The remainders read from last to first are the new digits. Example 2 below works this through.

Shortcuts between binary, octal and hex

Because 16 = 24 and 8 = 23, every hex digit stands for exactly 4 bits and every octal digit for exactly 3 bits. Split a binary number into groups from the right and translate each group:

DecimalBinaryHexDecimalBinaryHex
000000810008
100011910019
200102101010A
300113111011B
401004121100C
501015131101D
601106141110E
701117151111F

The standard form prints binary in these 4-bit groups, adding leading zeros to fill the first group. Its Size line counts the binary digits of the number without the sign or leading zeros, then divides by 8 and rounds up for bytes.

Two's complement on the keypad

The keypad keeps exactly 64 bits. A negative number −x is stored as 264 − x, the same pattern you get by inverting every bit of x and adding 1. HEX, OCT and BIN show that raw bit pattern; DEC reads it as signed, so a value whose top bit (bit 63) is 1 appears as a negative number.

Worked example

Example 1: binary 1101 0110 to the other bases

  1. Place values: 1 × 128 + 1 × 64 + 0 × 32 + 1 × 16 + 0 × 8 + 1 × 4 + 1 × 2 + 0 × 1 = 214.
  2. Hex, in 4-bit groups: 1101 = D and 0110 = 6, so D6.
  3. Octal, in 3-bit groups from the right: 11 | 010 | 110 = 3, 2, 6, so 326.

The standard form, with Input base Binary, shows Decimal 214, Octal 326, Hexadecimal D6 and Size "8 bits (1 byte) for the magnitude". Typing 11010110 or 0b1101_0110 gives the same result.

Example 2: decimal 500 to hex by repeated division

  1. 500 ÷ 16 = 31 remainder 4.
  2. 31 ÷ 16 = 1 remainder 15, which is F.
  3. 1 ÷ 16 = 0 remainder 1.
  4. Read the remainders from last to first: 1F4.

The form shows Binary 0001 1111 0100, Octal 764 and Size "9 bits (2 bytes) for the magnitude": 500 needs 9 binary digits, which is more than one byte.

Example 3: −10 in the form and on the keypad

In the standard form, −10 in decimal gives Binary -1010, Octal -12 and Hexadecimal -A, with the Size note "4 bits (1 byte) for the magnitude; negative numbers are shown with a minus sign, not as two's complement". This is the same style Python uses, where bin(-10) returns '-0b1010'.

On the keypad, choose DEC and press 0, −, 1, 0, =. The display shows -10, but the HEX line shows FFFFFFFFFFFFFFF6 and the BIN line ends in 11110110. That is 264 − 10 = 18,446,744,073,709,551,606, which is exactly what the form shows if you type 18446744073709551606. In an 8-bit byte, −10 would be 256 − 10 = 246 = F6 = 1111 0110, the same last eight bits.

Example 4: a number too big for 64 bits

Enter 18446744073709551616 (264) in the form. It shows Hexadecimal 10000000000000000 and Size "65 bits (9 bytes) for the magnitude", exactly. On the keypad the same digits wrap around to 0, because only the lowest 64 bits are kept.

How to use this calculator

  1. In the standard form, type the number in Value. Spaces and underscores between digits are ignored, a leading minus sign makes it negative, and an optional 0b, 0o or 0x prefix is allowed when it matches the base.
  2. Choose the Input base: Binary, Octal, Decimal or Hexadecimal. Letters A to F can be upper or lower case.
  3. Read the four conversions and the Size. If the Decimal line says, for example, "Not a valid binary (0 and 1) number", a digit does not belong to the base you chose.

Using the 64-bit keypad

  • Pick HEX (the default), DEC, OCT or BIN. Digit keys that do not exist in that base are disabled; switching modes keeps the value and changes only how the large display shows it.
  • The HEX, DEC, OCT and BIN lines always show all four bases. BIN shows all 64 bits in four groups of 16.
  • Click any bit in the bit row to flip it between 0 and 1; bit 63 is on the left and bit 0 on the right.
  • Operations run left to right in the order you press them, without the usual order of operations. ÷ drops any remainder, MOD gives the remainder, AC clears everything and ⌫ removes the last digit you typed.
  • With the page focused, you can also type 0 to 9 and A to F, use + − * /, press Enter or = for the result, Backspace to delete and Escape to clear.

Common mistakes

  • Typing commas or a decimal point: 1,000 and 12.5 are rejected as decimal numbers. Use 1000, or 1_000.
  • Leaving the wrong base selected: 0x1F with Decimal chosen is invalid, and 0b101 with Hexadecimal chosen is read as the hex number B101 (45,313).
  • Treating a keypad pattern as a new number: FFFFFFFFFFFFFFF6 is how 64 bits store −10.

New to bases? Start with binary numbers for beginners. Powers of 2 and 16 can be checked with the exponent calculator, and very long results are discussed in showing full numbers without scientific notation.

Sources

Frequently asked questions

Why does the keypad show FFFFFFFFFFFFFFF6 for −10 when the form shows -A?

They are two ways of writing the same number. The form uses sign and magnitude: a minus sign in front of the digits of 10. The keypad stores a fixed 64-bit pattern, and in two's complement −10 is 264 − 10, which is FFFFFFFFFFFFFFF6 in hex. The keypad's DEC line reads that pattern as signed and shows -10. Use the form when you want the plain signed value and the keypad when you need the 64-bit two's complement pattern.

Why does it say "Not a valid binary (0 and 1) number"?

The form checks every character against the base you chose instead of guessing. 102 contains a 2, so it is not binary. Decimal input rejects letters, commas and decimal points ("Not a valid decimal (0–9) number"), octal rejects 8 and 9, and hexadecimal rejects anything outside 0 to 9 and A to F. Spaces and underscores are fine, and a leading + sign is not accepted.

What do the prefixes 0x, 0b and 0o mean?

They mark hexadecimal, binary and octal numbers in programming languages such as Python, which uses 0x, 0b and 0o and also allows underscores to group digits, as in 0xDead_Beef. The form removes a prefix only when it matches the selected base, so 0x1F4 with Hexadecimal gives 500, while 0b101 with Hexadecimal is read as hex B101, because b is a hex digit.

How large a number can it convert?

The form uses exact whole-number arithmetic with no fixed limit, so 264 = 18,446,744,073,709,551,616 converts exactly. The keypad holds 64 bits. Its largest unsigned pattern is FFFFFFFFFFFFFFFF (18,446,744,073,709,551,615), which the DEC line shows as -1; its largest positive signed value is 7FFFFFFFFFFFFFFF (9,223,372,036,854,775,807). Adding 1 to that gives 8000000000000000, shown in DEC as -9223372036854775808, because the result wraps around.

Can it convert fractions such as 0.5 or 12.75?

No. Both tools work with whole numbers only, so a decimal point makes the form show "Not a valid decimal (0–9) number". Fractions in other bases use negative powers of the base and are not covered here.

Why is each hex digit worth 4 bits?

Because 16 = 24, the 16 hex digits match the 16 possible patterns of 4 bits, from 0000 to 1111. Two hex digits therefore describe one 8-bit byte: FF is 1111 1111, or 255. Octal digits match 3 bits in the same way, since 8 = 23.

How do AND, OR, XOR, NOT and the shifts work on the keypad?

They compare the two values bit by bit. In HEX mode, F0 AND 3C = 30, F0 OR 3C = FC and F0 XOR 3C = CC. NOT flips all 64 bits, so NOT 0 = FFFFFFFFFFFFFFFF (DEC -1). 1 << 4 = 10 hex (16). The >> key always shifts in zeros, so a negative value becomes positive: FFFFFFFFFFFFFFF6 >> 1 = 7FFFFFFFFFFFFFFB. ÷ and MOD also treat the 64 bits as unsigned, so dividing a negative number gives a large positive result, and dividing by 0 shows 0 rather than an error.

Why does 2 + 3 × 4 give 20 on the keypad?

The keypad applies each operation when you press the next one, so it works out 2 + 3 = 5 first and then 5 × 4 = 20. Algebra rules would give 14. Press = after each step, or enter the multiplication first: 3 × 4 + 2 = 14.