All Tools

Number Base Converter: Binary, Hex, Octal, Decimal

Convert whole numbers of any length exactly between binary, octal, decimal, hex and any base from 2 to 36, with BCD, Gray code, negabinary and two's complement. Runs in your browser. Nothing is uploaded.

Binary digits
Two's complement width

About the Number Base Converter

The Number Base Converter turns a whole number into every common representation at once. Type a value, pick the base it is written in, and the page shows it in binary, octal, decimal, hexadecimal and a custom base from 2 to 36, together with its BCD, Gray code, negabinary, negadecimal and two's complement forms. Each result has its own Copy button. Conversion is exact for numbers of any length, up to 10,000 digits, so 64-bit, 128-bit and longer values come out digit for digit. Everything runs in your browser; the numbers you type are never uploaded.

How to use it

Steps

  1. Choose the base of your input under From. Decimal is selected to start.
  2. Type or paste the number. Prefixes such as 0b, 0o and 0x are accepted for binary, octal and hex, spaces and underscores between digits are ignored, and a leading minus sign makes the number negative.
  3. Read the results. Every representation updates as you type.
  4. Use the options to change the output: Upper case for hex digits, Groups of 4 or Groups of 8 to split long bit strings, the custom base, and the two's complement width of 8, 16, 32 or 64 bits.

Privacy

The conversions are done by code on this page, in your browser. Nothing is sent to our servers, and nothing is kept once you close or reload the tab.

The representations

Positional bases

In base b each digit is worth b times the digit to its right. Binary uses the digits 0 and 1, octal 0 to 7, decimal 0 to 9 and hexadecimal 0 to 9 then a to f. Bases above 10 continue through the alphabet, so base 36 uses every digit and letter. Each hex digit stands for exactly four bits and each octal digit for three, which is why programmers prefer them to decimal for bit patterns.

BCD

Binary-coded decimal (8421 code) stores each decimal digit in its own four-bit nibble, so 1234 becomes 0001 0010 0011 0100. It is still used by real-time clock chips, seven-segment displays and some financial formats. When you convert from BCD, each nibble must be 0000 to 1001; the page names the first nibble that is not a decimal digit.

Gray code

The reflected binary Gray code changes exactly one bit between consecutive numbers, which prevents glitches in rotary encoders and Karnaugh maps. A number is encoded as b XOR (b >> 1) and decoded by XORing all of its right shifts. Gray code is defined for zero and positive numbers only.

Negabinary

Negabinary is base −2. Its digit positions are worth 1, −2, 4, −8 and so on, so every integer, positive or negative, is written with the digits 0 and 1 and no sign: 6 is 11010 and −3 is 1101.

Negadecimal

Negadecimal is base −10. Its digit positions are worth 1, −10, 100, −1,000 and so on, and it uses the ordinary digits 0 to 9 with no sign. 15 is written 195, because 1 × 100 − 9 × 10 + 5 = 15, and −11 is written 29, because 2 × (−10) + 9 = −11. To convert from negadecimal, choose it under From and type the digits without a minus sign.

Two's complement

Computers store signed integers in a fixed number of bits using two's complement: a negative number −n is stored as 2^width − n. At 8 bits, −1 is 11111111 and −128 is 10000000. Converting from two's complement reads the bit pattern back as a signed value at the chosen width; a pattern shorter than the width is padded with leading zeros. A value outside the range of the width, such as 128 at 8 bits, is reported instead of being silently wrapped.

Limits

Inputs are whole numbers only. Fractions and floating-point formats such as IEEE 754 are not converted. Up to 10,000 digits are accepted, which is far beyond any machine integer.

Related tools

The quick conversion pages open this tool with the right base chosen: Binary to Decimal, Decimal to Binary, Hex to Decimal and Decimal to Hex. To add, AND or shift binary and hex numbers, use the Binary Calculator. To turn text into binary or hex byte codes rather than numbers, use Text to Binary. For Roman numerals, see the Roman Numeral Converter.

Open-source credits

  • The converter is written for this site and uses no third-party library. Arithmetic uses the browser's built-in BigInt, specified in ECMA-262, the ECMAScript language specification.
  • Gray code follows the reflected binary code of Frank Gray's US patent 2,632,058, Pulse Code Communication (1953), and the tests check the sequence published as OEIS A003188.
  • Negabinary follows the base −2 positional system described in Donald Knuth's The Art of Computer Programming, volume 2, section 4.1, and the tests check OEIS A039724.
  • Negadecimal uses the same negative-radix division as negabinary, as introduced by Vittorio Grünwald in 1885, and the tests check the sequence published as OEIS A039723.
  • BCD uses the standard 8421 weighting, and two's complement follows the signed integer representation required by ISO/IEC 9899:2024 (C23).

Frequently asked questions

Are large numbers converted exactly?

Yes. The converter uses arbitrary-precision integers, so every digit is exact for values far beyond 64 bits. Calculators and spreadsheets use floating point and start rounding after about 15 to 17 decimal digits; this page does not. Inputs of up to 10,000 digits are accepted.

Can I paste numbers with 0x, 0b or 0o prefixes?

Yes. A 0x prefix is accepted for hexadecimal, 0b for binary and 0o for octal, in upper or lower case. Spaces and underscores between digits are ignored, so 0xFF_FF and ff ff are the same value, and a leading minus sign makes the number negative.

How do I convert a negative number to binary the way a computer stores it?

Read the Two's complement row and choose the width of 8, 16, 32 or 64 bits. At 8 bits, -1 is 11111111 and -128 is 10000000. The plain Binary row shows a minus sign followed by the magnitude instead. To go back, choose Two's complement under From and paste the bit pattern.

What is the difference between BCD and binary?

Binary writes the whole number in base 2, so 12 is 1100. BCD writes each decimal digit in its own four bits, so 12 is 0001 0010. BCD is used by clock chips and displays because each digit can be read separately. When converting from BCD, every nibble must be 0000 to 1001.

What are Gray code and negabinary used for?

Gray code changes exactly one bit between neighbouring numbers, which avoids reading errors in rotary encoders and simplifies Karnaugh maps. Negabinary is base -2, which writes every integer, positive or negative, without a sign. Both are shown for every number you enter.

Is my number sent anywhere?

No. The conversion is done by code on the page, in your browser. Nothing is uploaded and nothing is kept after you close the tab.

Other related tools