What is number base conversion?
Number base conversion writes the same whole number in another positional numeral system. Binary (base 2) is how computers store data, octal (base 8) appears in Unix file permissions, decimal (base 10) is everyday counting, and hexadecimal (base 16) is a compact way to write bytes, colours, and memory addresses. This converter shows a number in all four at once, exactly at any size, and writes negative numbers both with a sign and in two's complement.
Why numbers have different bases
The same value can be written in different number systems. Decimal (base 10) is what people use daily; binary (base 2) is how computers store everything; hexadecimal (base 16) is a compact way to write binary that programmers use for colours, memory addresses, and byte values; octal (base 8) appears in file permissions. Converting between bases lets you move between how a human, a program, and the hardware each prefer to see a number.
Each base uses a different set of digits (binary uses 0 and 1, and hexadecimal adds the letters A to F for the values ten to fifteen), but they all describe the same underlying quantity.
Where each base shows up
You will meet hexadecimal in CSS colours like #FF0000 and in hash values, binary when working with bitmasks and flags, and octal in Unix file permissions such as 755, which is 111 101 101 in binary: read, write, and execute for the owner, and read and execute for everyone else. Being able to convert quickly between them removes a common source of misread-value bugs.
Reading binary and hex quickly
A useful habit is to group binary digits in fours, because each group of four bits maps to exactly one hexadecimal digit. That makes 1111 the same as F and 1010 the same as A, so you can translate between binary and hex in your head once the sixteen patterns become familiar. The converter shows binary and hex in groups of four, and octal and decimal in groups of three, and you can type digits grouped the same way, with spaces or underscores.
Large numbers, exactly
JavaScript's ordinary numbers keep only about 16 significant digits, so a converter built on parseInt turns 9007199254740993 into 9007199254740992 and a 64-bit value such as FFFFFFFFFFFFFFFF into 18446744073709552000. This converter uses BigInt, JavaScript's arbitrary-precision integer, so every digit is exact at any size: FFFFFFFFFFFFFFFF is 18446744073709551615, and a 64-digit hexadecimal hash converts to binary and decimal without losing a digit.
Negative numbers and two's complement
A negative number is written with its sign first, as programming languages expect: -255 is -0xFF in hexadecimal and -0b11111111 in binary. Hardware stores signed integers differently, in two's complement, where -1 is all ones. So for a negative number the converter also shows its two's complement at the smallest of 8, 16, 32, 64, and 128 bits that holds it: -1 is 0xFF as an 8-bit value, and -129, which doesn't fit in 8 bits, is 0xFF7F as a 16-bit value. It also shows what the same bits mean read as an unsigned number.
How to convert a number between bases
- 1Choose the input base. Pick Binary, Octal, Decimal, or Hexadecimal. Switching later rewrites the number you've entered in the new base.
- 2Enter a whole number. Type or paste it, with or without the base's prefix (0b, 0o, 0x) and a minus sign. Digits can be grouped with spaces or underscores. If a character isn't valid, the message says which one.
- 3Copy the base you need. Every base updates as you type. Copy one value, or Copy output for all of them; negative numbers also show their two's complement.
Examples
Decimal to the other bases
Input base: Decimal.
Input
255
Output
Binary 11111111 · Octal 377 · Hexadecimal FF
Hexadecimal to decimal
Input base: Hexadecimal; the 0x prefix is optional.
Input
0x1A
Output
Decimal 26 · Binary 11010 · Octal 32
Grouped binary
Input base: Binary; spaces between groups are ignored.
Input
1101 0110
Output
Decimal 214 · Hexadecimal D6 · Octal 326
Unix file permissions
Input base: Octal.
Input
755
Output
Binary 111101101 · Decimal 493 · Hexadecimal 1ED
A 64-bit value, exactly
Input base: Hexadecimal; parseInt would give 18446744073709552000.
Input
FFFFFFFFFFFFFFFF
Output
Decimal 18446744073709551615 · 64 bits
Negative number
Input base: Decimal.
Input
-1
Output
Hexadecimal -1 · Two's complement (8-bit) 0xFF, 255 unsigned
Negative number wider than 8 bits
Input base: Decimal.
Input
-129
Output
Hexadecimal -81 · Two's complement (16-bit) 0xFF7F, 65407 unsigned
Number bases
The four bases, their digits, and the prefix most languages use for them.
| Base | Name | Digits | Prefix |
|---|---|---|---|
| 2 | Binary | 0–1 | 0b |
| 8 | Octal | 0–7 | 0o |
| 10 | Decimal | 0–9 | none |
| 16 | Hexadecimal | 0–9, A–F | 0x |
Frequently asked questions
What is hexadecimal used for?
Hex is a compact way to write binary: two hex digits equal one byte. It is used for CSS colours, memory addresses, hash values, and byte-level data.
Why do computers use binary?
Hardware stores data as on/off states, which map directly to the 1s and 0s of binary. Every other base is a convenience for humans reading that data.
What do the 0x, 0b, and 0o prefixes mean?
They mark the base of a number literal: 0x for hexadecimal in C, JavaScript, Python, and most other languages, 0b for binary in JavaScript, Python, Rust, Java, and C#, and 0o for octal in JavaScript, Python, and Rust. The converter accepts the input base's prefix, in either case, or none; another base's prefix gets a message saying which base to choose.
Can it convert very large numbers?
Yes, exactly. It uses BigInt, so numbers of any length convert without rounding: FFFFFFFFFFFFFFFF is 18446744073709551615, where JavaScript's ordinary numbers would give 18446744073709552000.
How are negative numbers shown?
With the sign first, as code writes them: -255 is -0xFF and -0b11111111. The converter also shows the two's complement, how a signed integer is stored, at the smallest of 8, 16, 32, 64, and 128 bits that holds the number: -1 is 0xFF in 8 bits, and -129 is 0xFF7F in 16 bits.
Can I group digits with spaces or underscores?
Yes. A single space or underscore between digits is ignored, so 1101 0110 and 1_000_000 both work. Commas aren't accepted, because a comma means a thousands separator in some places and a decimal point in others.
Does it convert fractions?
No. It converts whole numbers only; input such as 3.14 or 1e3 gets a message saying so.
What is a nibble?
Four bits, half a byte, which is exactly one hexadecimal digit. Two nibbles make one byte, written as two hex characters.
Is the conversion private?
Yes. It runs in your browser, and nothing you enter is sent to a server. The only exception is the Share link button, which uploads the current output (the number in every base) and the input base when you click it.
Is it free?
Yes — free with no limits.