Number Base Converter

Convert binary, hex, octal, decimal and any base from 2 to 36, with integers of any size, exact fractions and two's complement at 8, 16, 32 or 64 bits.

The interactive tool loads here when JavaScript runs.

About this tool

What is the Number Base Converter?

Type a number and the Number Base Converter shows it in binary, octal, decimal and hexadecimal at once, plus any other base from 2 to 36 you pick. It reads the 0x, 0o and 0b prefixes used in JavaScript, Python, Rust and C, ignores _ separators, and groups the output digits in fours or threes so long values stay readable.

Integers are handled as BigInt, so a 64-bit mask, the 32 hex digits of a UUID (without its hyphens) or a 200-digit number converts exactly instead of losing its last digits past 2^53 the way parseInt does. Fractions convert exactly too: 10.625 is 1010.101 in binary, and 0.1 is 0.0(0011), with the repeating block in parentheses rather than a long row of digits that stops at some arbitrary point.

Pick a width (8, 16, 32, 64 or any width up to 1024 bits) to see the two's complement bit pattern of a negative number, its signed and unsigned readings, the valid range and the bytes in big-endian and little-endian order. Tick "read the input as a bit pattern" to go the other way: FFD6 at 16 bits is -42.

  • Binary, octal, decimal and hex side by side, plus any base from 2 to 36
  • Arbitrary-size integers with BigInt, no 2^53 limit
  • Exact fractions with repeating digits marked in parentheses
  • Two's complement at 8, 16, 32, 64 or any width up to 1024 bits, with signed and unsigned readings
  • Bytes in big-endian and little-endian order
  • Accepts 0x, 0o and 0b prefixes and _ separators, copy buttons and shareable links, runs in your browser
Read the guide: Binary, Hex and IEEE 754 Floats, Bit by Bit

Updated

How to use the Number Base Converter

  1. Type the number. Use a 0x, 0o or 0b prefix, or choose the input base from the list (2 to 36). Separators such as _ and spaces are ignored.
  2. Read the binary, octal, decimal and hex results, and set "Extra output base" for any other base, such as 36 for short IDs.
  3. For a signed integer, choose a width under Two's complement to see its bit pattern, signed and unsigned values and byte order.
  4. To decode a raw value from a register or a hex dump, choose the width and tick "Read the input as a bit pattern".
  5. Copy any row, copy all the results, or share a link that reopens the same conversion.

Worked examples

Hex to binary and decimal

Input

0xDEADBEEF

Output

Binary 1101 1110 1010 1101 1011 1110 1110 1111, decimal 3,735,928,559

Each hex digit maps to four bits (D = 1101, E = 1110). Read as a signed 32-bit integer the same pattern is -559,038,737, because its top bit is set.

A negative number in a 16-bit register

Input

-42 with the width set to 16-bit

Output

Pattern 1111 1111 1101 0110 = 0xFFD6, unsigned reading 65,494

42 is 0000 0000 0010 1010; inverting gives 1111 1111 1101 0101 and adding one gives FFD6. In memory on a little-endian machine the bytes are D6 FF.

Past the 2^53 limit of a JavaScript number

Input

0x20000000000001

Output

9,007,199,254,740,993

parseInt("20000000000001", 16) returns 9,007,199,254,740,992 because a double cannot hold the final 1. BigInt keeps every digit.

A fraction that never ends in binary

Input

0.1

Output

Binary 0.0(0011), hex 0.1(9), octal 0.0(6314)

One tenth needs a factor of 5 in the denominator, which no power of two has, so the binary digits repeat forever. Floats have to round it; the IEEE 754 Float Converter shows exactly where.

Background and insight

A positional numeral system writes a number as digits times powers of a base: FF in base 16 is 15 × 16 + 15 = 255, and 11111111 in base 2 is the same 255 as eight ones. Hexadecimal and octal survive in programming because each hex digit is exactly four bits and each octal digit three, so they are compact spellings of binary. Bases above 16 borrow letters, which is why base 36 (0 to 9 then a to z) is the largest base that JavaScript's Number.prototype.toString and parseInt accept, and the limit this tool uses.

Negative integers in hardware are stored in two's complement: to negate a value, invert every bit and add one. In 8 bits, 5 is 00000101 and -5 is 11111011. The top bit then carries a weight of -2^(n-1) instead of +2^(n-1), which gives the asymmetric range -128 to 127 for a signed byte and lets the same adder circuit handle signed and unsigned numbers. The same bit pattern means different numbers depending on the type: 11001000 is 200 as a uint8 and -56 as an int8.

ECMAScript has had BigInt since ES2020, with BigInt.asIntN and BigInt.asUintN to wrap a value into a fixed width exactly as a C cast does. This tool uses them for the two's complement view, so a value that does not fit is shown wrapped modulo 2^n and flagged rather than silently clipped. Fractions are converted by long division in the target base; a remainder seen before marks the start of a repeating block, which is how you can tell that 0.1 has no finite binary form.

Common use cases

  • Reading registers and bit masks

    Turn a hex value from a datasheet or debugger into bits to see which flags are set, or build a mask in binary and copy it as hex.

  • Signed values in dumps and protocols

    Decide whether FFD6 in a packet or sensor reading means 65,494 or -42 by reading it as a 16-bit two's complement pattern.

  • Computer science homework

    Check base conversions, two's complement negation and fraction expansions, with the positional expansion shown for short integers.

  • Compact IDs in base 36

    Turn a large integer into a short base 36 string of digits and letters, or decode one back, the same conversion as BigInt toString(36) in JavaScript.

Tips and limitations

  • A leading 0x, 0o or 0b is only read as a prefix when it names the chosen base. In base 16, "0b1" is the hex number B1, exactly as parseInt("0b1", 16) reads it.
  • Two's complement applies to whole numbers. With a fractional input the tool converts the fraction but leaves the bit pattern out, because fixed-width integers have no fractional bits.
  • If a value does not fit the width, the pattern shown is the value modulo 2^n, the same result a C cast or BigInt.asUintN gives, and a warning says so.
  • Fractions are expanded to 64 digits at most. When the digits neither end nor start repeating within that, the result ends in "..." and a warning appears.
  • Floating-point numbers are not stored as a plain binary fraction. Use the IEEE 754 Float Converter to see the sign, exponent and fraction bits of a float or double.

Sources and further reading

  1. ECMAScript Language Specification: Numeric Literals, Ecma International TC39. The 0x, 0o and 0b prefixes and _ separators the tool accepts
  2. BigInt, MDN Web Docs. Arbitrary-size integers, toString(radix) and the asIntN and asUintN wrappers
  3. Two's Complement, Cornell University. Negation by inverting and adding one, and the signed range

Frequently asked questions

How do I convert hexadecimal to binary by hand?

Replace each hex digit with its four-bit pattern: 0 = 0000, 9 = 1001, A = 1010, F = 1111. 0x3C becomes 0011 1100. Going back, split the binary into groups of four from the right and replace each group with its hex digit. Octal works the same way with groups of three.

How do I find the two's complement of a negative number?

Write the positive value in the chosen width, invert every bit and add one. For -5 in 8 bits: 5 is 00000101, inverted 11111010, plus one 11111011 (0xFB). Reading it back works the same way: invert and add one to get the magnitude.

Why does the same hex value show two different decimal numbers?

A bit pattern has no sign of its own; the type decides. With its top bit set, 0xC8 is 200 as an unsigned byte and -56 as a signed byte. The tool shows both readings when you pick a width.

What is the largest base this converter supports?

Base 36, which uses the digits 0 to 9 and the letters a to z. It is also the largest radix JavaScript's toString and parseInt accept. Letters are read case-insensitively.

Why does 0.1 not convert to a finite binary number?

A fraction terminates in a base only if every prime factor of its denominator divides that base. 1/10 has the factor 5 and 2 does not, so its binary digits repeat: 0.0(0011). The same fraction is finite in base 10 and base 20.

Can it convert numbers bigger than 64 bits?

Yes. Integers are handled as BigInt and limited only by an input length of 4,096 characters. The two's complement view goes up to 1,024 bits.

Is there an in-depth guide to the Number Base Converter?

Yes. “Binary, Hex and IEEE 754 Floats, Bit by Bit” covers the background, how it works, common pitfalls and worked examples. Read the full guide.