Number base converter

Convert integers between binary, octal, decimal, hexadecimal and any base from 2 to 36, with exact big numbers, negatives and two’s complement.

  • Runs locally
  • Free

Use the tool

Your files are processed in your browser and are not uploaded to a server.

About this tool

A number base converter: type an integer in the binary, octal, decimal, hexadecimal or any base 2–36 field and every other base updates at once. It uses BigInt, so values up to 4,096 decimal digits stay exact; it accepts 0b, 0o and 0x prefixes, underscores and negative numbers, and shows the two’s-complement pattern for 8, 16, 32 and 64 bits.

Typical uses

  • Turn a hex color, memory address or error code into decimal
  • See the two’s-complement bits of a negative number in an 8-bit or 32-bit integer
  • Check how a big integer ID above 2^53 is written in other bases

How to use

  1. Type an integer in any field: binary, octal, decimal, hexadecimal, or any base from 2 to 36 picked in the menu. Prefixes 0b, 0o and 0x, spaces or underscores as separators and a minus sign are accepted.

  2. The other fields update as you type; choose upper-case letters, prefixes and grouping, then copy any field. Under “Two’s complement”, pick 8, 16, 32 or 64 bits to see the bit pattern and its signed and unsigned readings.

Good to know

Uses BigInt, so every integer below 10^4096 (up to 4,096 decimal digits) converts exactly, with none of the precision loss ordinary JavaScript numbers have above 2^53 − 1. Whole numbers only, no fractions. Values outside the chosen width are reported as an overflow and only the low bits are shown. Runs in your browser.

Positional notation: one number, many spellings

A base (radix) sets the weight of each position. In base b, the k-th digit from the right (counting from 0) is worth b^k, and the value is the sum of each digit times its weight. Hexadecimal writes 10–15 as A–F and base 36 goes up to Z (35), so 2–36 are all the bases that “0–9 plus 26 letters” can spell. Examples: hex 2F: 2×16¹ + 15×16⁰ = 47; binary 1011: 1×2³ + 0×2² + 1×2¹ + 1×2⁰ = 11; octal 755: 7×8² + 5×8¹ + 5×8⁰ = 493; base-36 ZZ = 1295.

DecimalBinary (4 bits)OctalHex
0000000
1000111
2001022
3001133
4010044
5010155
6011066
7011177
81000108
91001119
10101012A
11101113B
12110014C
13110115D
14111016E
15111117F
16100002010

This table and every figure below are computed by the tool’s own conversion functions when the page is built.

Powers of two and common values

PowerDecimalHex
2^4160x10
2^82560x100
2^1010240x400
2^16655360x1 0000
2^24167772160x100 0000
2^3121474836480x8000 0000
2^3242949672960x1 0000 0000
2^5390071992547409920x20 0000 0000 0000
2^6392233720368547758080x8000 0000 0000 0000
2^64184467440737095516160x1 0000 0000 0000 0000
DecimalBinaryOctalHex
2551111 11113770xFF
2561 0000 00004000x100
1024100 0000 000020000x400
655351111 1111 1111 11111777770xFFFF
2147483647111 1111 1111 1111 1111 1111 1111 1111177777777770x7FFFFFFF
42949672951111 1111 1111 1111 1111 1111 1111 1111377777777770xFFFFFFFF

255 is a byte (8 bits) of ones; 65535 is the largest unsigned 16-bit integer; 2147483647 (0x7FFFFFFF) is the largest signed 32-bit integer and 4294967295 (0xFFFFFFFF) the largest unsigned one. 1024 = 2^10 is the step between KiB and bytes.

Why one hex digit is exactly four bits

16 = 2^4, so every hex digit stands for exactly 4 binary digits (a nibble), and conversion needs no division, only a digit-by-digit lookup. Likewise 8 = 2^3, so one octal digit is 3 bits. 0xDEADBEEF grouped by four is 1101 1110 1010 1101 1011 1110 1110 1111, or 3735928559 in decimal; octal 755 grouped by three is 111 101 101. Ten is not a power of two, so decimal has no such digit-to-bits mapping, which is why programmers read memory and bit masks in hex.

In the tool, “Binary groups” splits binary every 4 or 8 digits, “Hex groups” splits hex every 2 digits (one byte) or 4, and “Group separator” chooses a space or an underscore. “Upper-case letters (A–F)” sets the case of A–F, and “Show prefixes (0b, 0o, 0x)” adds 0b, 0o and 0x so results paste straight into code.

Two’s complement: how computers store negative numbers

Fixed-width integers store a negative value v in w bits as 2^w + v. In 8 bits, −1 is stored as 2^8 − 1 = 255, which is 1111 1111. By hand: “invert and add one”. 1 is 0000 0001; inverting every bit gives 1111 1110; adding 1 gives 1111 1111. A leading 1 means negative, so the same bits have two readings, “Read as signed” and “Read as unsigned”. The table comes from the tool’s “Two’s complement” panel:

ValueBitsBit patternHexRead as unsigned
−181111 1111FF255
−1161111 1111 1111 1111FFFF65535
−1321111 1111 1111 1111 1111 1111 1111 1111FFFF FFFF4294967295
−12881000 000080128
−128161111 1111 1000 0000FF8065408
−128321111 1111 1111 1111 1111 1111 1000 0000FFFF FF804294967168
12780111 11117F127
127160000 0000 0111 1111007F127
127320000 0000 0000 0000 0000 0000 0111 11110000 007F127
WidthSigned rangeUnsigned range
8−128 … 1270 … 255
16−32768 … 327670 … 65535
32−2147483648 … 21474836470 … 4294967295
64−9223372036854775808 … 92233720368547758070 … 18446744073709551615
  • 128 does not fit the signed 8-bit range but does fit the unsigned one: the pattern is 1000 0000, which reads as -128 when signed. In the same way 255 (0xFF) reads as -1.
  • 256 is outside both 8-bit ranges. The tool reports the overflow and shows the low 8 bits, 0000 0000, which is exactly what a cast such as (byte) 256 in Java or (uint8_t) 256 in C produces.
  • Widening a negative number fills with ones: −128 in 16 bits is 0xFF80. Extending signed data therefore needs sign extension, not zero padding.

JavaScript Number vs BigInt: why big numbers go wrong

A JavaScript Number is an IEEE 754 double with 53 significant bits. Number.MAX_SAFE_INTEGER is 9007199254740991, that is 2^53 − 1 (0x1FFFFFFFFFFFFF). Above it integers are no longer guaranteed exact: in a browser, Number('9007199254740993') gives 9007199254740992, and parseInt('ffffffffffffffff', 16) gives 18446744073709552000 while the true value is 18446744073709551615. This tool uses BigInt (arbitrary-precision integers) throughout, so values up to 4096 decimal digits (13607 binary digits) convert exactly.

  • parseInt does not understand the 0b prefix: parseInt('0b101') returns 0, while BigInt('0b101') returns 5.
  • Source code may use separators such as 1_000_000, but at run time Number('1_000') is NaN. This tool ignores underscores and spaces in what you type.
  • Number.isSafeInteger(2 ** 53) is false. 64-bit IDs from a server should be kept as strings or parsed with BigInt.

Practical examples: file permissions, colors and 2038

Unix chmod writes permissions as three octal digits for owner, group and others. Each octal digit is exactly three bits: read (4), write (2) and execute (1).

OctalBinaryPermissionsTypical use
755111 101 101rwxr-xr-xDirectories and executable scripts
644110 100 100rw-r--r--Ordinary files
600110 000 000rw-------Private keys and other owner-only files

A web color #RRGGBB is three bytes in hex: #FF8800 splits into FF, 88 and 00, which is RGB(255, 136, 0); #336699 is RGB(51, 102, 153). The CSS short form #F80 doubles each digit, giving #FF8800.

0x7FFFFFFF = 2147483647 is the largest number of seconds a signed 32-bit integer can hold. Systems that store Unix time that way overflow after 2038-01-19T03:14:07Z (UTC): the “year 2038 problem”.

Input rules and limits

  • Type in any field and the others update as you type. The binary, octal and hex fields accept their own 0b, 0o and 0x prefixes; a prefixed number such as 0x1F typed in the decimal field is read in the prefix’s base.
  • Spaces and underscores between digits are ignored, a leading + or − sets the sign, and letters may be upper or lower case.
  • A wrong digit is pointed out by position. Typing 102 in the binary field shows: ““2” is not a digit in base 2 (character 3). Allowed digits: 0–1.”
  • Values must be below 10^4096. Whole numbers only: a decimal fraction like 0.1 repeats forever in binary and has no exact finite form.
  • “Two’s complement” offers 8, 16, 32 and 64 bits (“Bit width”); the case of the hex pattern follows “Upper-case letters (A–F)”.

Sources

Frequently asked questions

What is −1 in binary?

Mathematically it is just −1. Computers store it in two’s complement: 1111 1111 (0xFF) in 8 bits, 0xFFFF FFFF in 32 bits. Pick the width under “Two’s complement” to see it.

Why does 0xFF show −1 in the two’s complement panel?

The same bits can be read as unsigned (255) or signed (−1). The tool shows both readings.

Can it convert fractions?

No, whole numbers only. Decimal fractions such as 0.1 repeat forever in binary and cannot be written exactly.