Number Base Converter

Convert between binary, octal, decimal and hex.

About this tool

Type a number in binary, octal, decimal or hexadecimal and see it in all the others, along with its bits grouped into bytes. Handles arbitrarily large integers and recognises 0x, 0b and 0o prefixes.

How to use it

  1. Type a number into any of the four fields: binary, octal, decimal or hexadecimal.
  2. The other fields update instantly. Prefixes like 0x, 0b and 0o are accepted.
  3. Check the bits panel to see the value split into bytes.

Questions

How big a number can it handle?
Any size. It uses JavaScript BigInt, so there is no 32-bit or 64-bit limit and no rounding.
Why do hex numbers start with 0x?
It is a convention from C, now used by most languages, to show that the digits are hexadecimal. Similarly 0b marks binary and 0o marks octal.
Where is octal still used?
Mainly for Unix file permissions, where 755 means rwxr-xr-x. Each octal digit maps neatly onto three permission bits.
How do I convert hex to ASCII text?
This tool converts numbers, not strings. In hex text, each pair of digits is one byte, which you look up in an ASCII table: 48 65 6C 6C 6F spells “Hello”. On the command line, echo 48656c6c6f | xxd -r -p turns a hex string back into text.
Can it convert fractions or numbers with a decimal point?
No, only whole numbers. Fractions are tricky in binary anyway: 0.1 in decimal has no exact binary form and repeats forever, which is why 0.1 + 0.2 isn’t exactly 0.3 in most programming languages. Floating-point values are stored in the IEEE 754 format, not as plain binary integers.
What is the largest number that fits in 8, 16, 32 or 64 bits?
Unsigned, it is 2ⁿ − 1: 255, 65,535, 4,294,967,295 and 18,446,744,073,709,551,615. Signed values reach about half that, such as 2,147,483,647 for 32 bits. JavaScript numbers are only exact up to 9,007,199,254,740,991, so this tool uses BigInt to stay precise beyond that.

How to convert binary to decimal, and back

Each digit of a binary number is worth a power of two, starting with 1 on the right. To convert 1011 to decimal, add up the positions that hold a 1: 8 + 0 + 2 + 1 = 11. Hexadecimal works the same way with powers of 16, so 0x2F is 2 × 16 + 15 = 47. Octal uses powers of eight. One rule covers every base: each digit times the base raised to its position.

To go the other way, divide by the target base repeatedly and write down the remainders from last to first. Dividing 11 by 2 again and again leaves remainders 1, 1, 0 and 1, which read backwards give 1011. With this number base converter you just type into any field and the other three update. In code, JavaScript has parseInt(text, 2) and n.toString(16), and Python has int(text, 2) and hex(n).

Why do programmers use hexadecimal?

One hex digit stands for exactly four bits, so two hex digits describe one byte. That makes hex a compact, readable way to write binary data: 11111111 is FF, and any 32-bit value fits in eight characters. You meet it in memory addresses, colour codes like #FF8800, hashes, MAC addresses, Unicode code points such as U+1F680, and the byte dumps printed by tools like xxd and hexdump.

The bits panel here shows the link directly. The value is padded to whole bytes, and each group of eight bits is shown with its two-digit hex value underneath. 48879 becomes 10111110 11101111, labelled BE and EF, which is why it reads as 0xBEEF. This makes it easy to check flags, bit masks and byte boundaries. The Subnet Calculator applies the same binary view to IPv4 addresses and netmasks.

How negative numbers work in binary: two’s complement

Computers usually store signed integers in two’s complement. To write −1 in 8 bits, invert every bit of 1 and add one: 00000001 becomes 11111110, plus one gives 11111111, or 0xFF. The top bit acts as the sign, so an 8-bit signed value ranges from −128 to 127, while the same bits read as unsigned run from 0 to 255. The bit pattern is identical; only the interpretation changes.

This converter works with plain integers, not fixed-width registers. Type -5 and you get -101 in binary and -5 in hex, with the minus sign kept in front instead of a two’s complement pattern. To get the 8-bit pattern of a negative number, add 256 first: −5 + 256 = 251, which is 0xFB. For 32 bits, add 4294967296. Spaces and underscores are ignored, so 1111_1011 works as input.

Decimal, hex, binary and octal table

The numbers you will look up most often, in all four bases.

DecimalHexadecimalBinaryOctal
00x000000o0
10x100010o1
20x200100o2
30x300110o3
40x401000o4
50x501010o5
60x601100o6
70x701110o7
80x810000o10
90x910010o11
100xA10100o12
110xB10110o13
120xC11000o14
130xD11010o15
140xE11100o16
150xF11110o17
160x100001 00000o20
320x200010 00000o40
640x400100 00000o100
1000x640110 01000o144
1270x7F0111 11110o177
1280x801000 00000o200
2550xFF1111 11110o377
2560x1000001 0000 00000o400
5120x2000010 0000 00000o1000
10000x3E80011 1110 10000o1750
10240x4000100 0000 00000o2000
40960x10000001 0000 0000 00000o10000
655350xFFFF1111 1111 1111 11110o177777

Something not working, or a result looks wrong? Report a problem with this tool