Hex Converter — Hex, Decimal, Binary & Octal
Text to ASCII Codes
How This Hex Converter Works
Type a number into any of the five fields and the other four update as you type. The converter covers the four bases programmers actually use — decimal (base 10), hexadecimal (base 16), binary (base 2) and octal (base 8) — plus an "any base" field for everything from base 2 to base 36. Each field accepts the prefix its base uses in code: 0x for hex, 0b for binary and 0o for octal. Spaces, underscores and commas are ignored, so you can paste 0b1111_1111, DE AD BE EF or 3,735,928,559 straight from source code or a log file.
Every conversion uses JavaScript's BigInt, so the result is exact at any size — 64-bit, 128-bit, or a 4,000-digit number. Most quick converters use ordinary JavaScript numbers, which are only exact up to 253 − 1, and they round anything larger without saying so. This one tells you when that would happen: enter 9007199254740993 and the info line notes that a JavaScript Number would round it to 9007199254740992.
Below the fields you get the working for small values. Type 2F in the hex field and you see 2×161 + 15×160 = 32 + 15 = 47; type 47 in the decimal field and you see the repeated division that produces 2F and 101111. Tick Two's complement to work with signed integers at a fixed width of 8, 16, 32, 64 or 128 bits, and Group digits to split long outputs into readable blocks.
Hex, Binary, Octal and Decimal Conversion Table
The first seventeen values show the pattern: hex runs out of single digits at 15 (F), binary doubles its length at every power of two, and octal rolls over at 8. The values after that are the ones you meet in practice — byte limits, powers of two and the 16-bit maximum.
| Decimal | Hex | Binary | Octal |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 |
| 2 | 2 | 10 | 2 |
| 3 | 3 | 11 | 3 |
| 4 | 4 | 100 | 4 |
| 5 | 5 | 101 | 5 |
| 6 | 6 | 110 | 6 |
| 7 | 7 | 111 | 7 |
| 8 | 8 | 1000 | 10 |
| 9 | 9 | 1001 | 11 |
| 10 | A | 1010 | 12 |
| 11 | B | 1011 | 13 |
| 12 | C | 1100 | 14 |
| 13 | D | 1101 | 15 |
| 14 | E | 1110 | 16 |
| 15 | F | 1111 | 17 |
| 16 | 10 | 10000 | 20 |
| 32 | 20 | 100000 | 40 |
| 64 | 40 | 1000000 | 100 |
| 100 | 64 | 1100100 | 144 |
| 127 | 7F | 1111111 | 177 |
| 128 | 80 | 10000000 | 200 |
| 255 | FF | 11111111 | 377 |
| 256 | 100 | 100000000 | 400 |
| 1000 | 3E8 | 1111101000 | 1750 |
| 1024 | 400 | 10000000000 | 2000 |
| 4096 | 1000 | 1000000000000 | 10000 |
| 65535 | FFFF | 1111111111111111 | 177777 |
Hex to Decimal
Hexadecimal is positional, exactly like decimal, but each place is worth sixteen times the one to its right instead of ten. The digits run 0–9 and then A–F for ten to fifteen. To convert hex to decimal, multiply each digit by 16 raised to its position (counting from 0 on the right) and add the results.
Example: 2F. 2 is in the 16s place and F (15) in the 1s place: 2×16 + 15×1 = 32 + 15 = 47.
Example: 7E4. 7×256 + 14×16 + 4×1 = 1792 + 224 + 4 = 2020.
Longer values work the same way; there are just more places. DEADBEEF, the classic debugging marker, is 3,735,928,559 — a full 32-bit value. Hex is also the format of every digest the hash generator prints: a SHA-256 hash is a 256-bit number written as 64 hex digits, and you can paste one into the hex field to see it in decimal.
Decimal to Hex
Going the other way, divide by 16 repeatedly and keep the remainders. The first remainder is the rightmost hex digit; read the remainders from the last one back to the first to get the answer. Remainders from 10 to 15 become A–F.
Example: 47. 47 ÷ 16 = 2 remainder 15 (F); 2 ÷ 16 = 0 remainder 2. Reading bottom to top gives 2F.
Example: 1000. 1000 ÷ 16 = 62 remainder 8; 62 ÷ 16 = 3 remainder 14 (E); 3 ÷ 16 = 0 remainder 3. The answer is 3E8. The converter shows these division steps for any decimal input below 264.
Two values worth memorising: 255 is FF, the largest byte, and 65,535 is FFFF, the largest 16-bit value. Every FF pair in a hex string is one byte with all eight bits set.
Binary to Decimal
Binary has two digits, 0 and 1, and each place is worth twice the one to its right: 1, 2, 4, 8, 16, 32, 64, 128 and so on. To convert binary to decimal, add the place values wherever there is a 1.
Example: 101101. Reading from the left, the places are 32, 16, 8, 4, 2 and 1. The 1s sit under 32, 8, 4 and 1, so the value is 32 + 8 + 4 + 1 = 45. The tool's working panel writes this out as 1×25 + 0×24 + 1×23 + 1×22 + 0×21 + 1×20.
Eight ones, 11111111, is 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255. That is why a byte holds 256 different values, 0 to 255.
Decimal to Binary
There are two hand methods. The first is the same repeated division as for hex, dividing by 2: the remainders, read from the bottom up, are the bits. For 45 that gives 45→22 r1, 22→11 r0, 11→5 r1, 5→2 r1, 2→1 r0, 1→0 r1, so the answer is 101101.
The second is often faster in your head: subtract the largest power of two that fits, write a 1 in that place, and repeat with what is left. For 156: 128 fits (28 left), 64 and 32 do not, 16 fits (12 left), 8 fits (4 left), 4 fits (0 left), and 2 and 1 do not. The bits for 128, 64, 32, 16, 8, 4, 2, 1 are therefore 10011100.
If you need text rather than a number in binary — the letters of a word as bytes — use the binary translator, which encodes text as UTF-8 and handles the reverse direction too.
Hex to Binary
This is the easiest conversion of all, and the reason programmers use hex in the first place: one hex digit is exactly four bits. Replace each hex digit with its four-bit pattern and you are done — no arithmetic needed.
| 0 = 0000 | 1 = 0001 | 2 = 0010 | 3 = 0011 |
| 4 = 0100 | 5 = 0101 | 6 = 0110 | 7 = 0111 |
| 8 = 1000 | 9 = 1001 | A = 1010 | B = 1011 |
| C = 1100 | D = 1101 | E = 1110 | F = 1111 |
Example: A7. A is 1010 and 7 is 0111, so A7 is 10100111 (167 in decimal).
Example: F00D. 1111 0000 0000 1101 gives 1111000000001101. Tick Group digits in the tool to see binary output in blocks of four, so each block lines up with one hex digit.
Binary to Hex
Reverse the table: split the binary number into groups of four starting from the right, pad the leftmost group with zeros, and replace each group with its hex digit.
Example: 11010110. The groups are 1101 and 0110, which are D and 6: D6 (214 in decimal).
Example: 101101. Six bits do not divide into fours, so pad on the left: 0010 1101, which is 2D (45). Grouping from the left instead, and padding on the right, would give 1011 0100 = B4, which is a different number — the most common hand-conversion mistake.
Octal to Decimal, Binary and Hex
Octal (base 8) uses the digits 0–7, and each octal digit is exactly three bits. It survives mainly in Unix file permissions, where each digit packs the read (4), write (2) and execute (1) bits for owner, group and others.
Example: chmod 755. 7 = 111, 5 = 101, 5 = 101, so 755 is 111101101 in binary — rwx for the owner, r-x for everyone else. As a decimal number it is 7×64 + 5×8 + 5 = 493, and in hex 1ED. Permission 644 is 420 in decimal and 110100100 in binary.
Two's Complement: Negative Numbers in Hex and Binary
Computers store signed integers in two's complement: for a width of N bits, a negative value −x is stored as the unsigned pattern 2N − x. The top bit then works as a sign bit, and ordinary addition just works. Tick Two's complement, choose a width, and type a negative number in the decimal field to see its stored pattern; or type a pattern in the hex, binary or octal field to see the signed value it represents.
| Width | Decimal | Hex pattern | Binary pattern |
|---|---|---|---|
| 8-bit | −1 | FF | 11111111 |
| 8-bit | −5 | FB | 11111011 |
| 8-bit | −128 | 80 | 10000000 |
| 16-bit | −2 | FFFE | 1111111111111110 |
| 32-bit | −1 | FFFFFFFF | 32 ones |
| 32-bit | −2,147,483,648 | 80000000 | 1 then 31 zeros |
The same pattern means different things at different widths. 10000000 read as signed 8-bit is −128; switch the width to 16-bit and the same bits are +128, because the top bit of a 16-bit value is now a zero you did not type. Each width also has a range: signed 8-bit covers −128 to 127, so entering 200 shows an "out of range" error instead of silently wrapping.
With two's complement switched off, the converter does plain mathematics: −255 becomes -FF in hex and -11111111 in binary, with a minus sign — the same sign-and-magnitude form that Python's hex(-255) ('-0xff') and JavaScript's (-255).toString(16) ("-ff") print.
Why Large Numbers Need BigInt
A JavaScript Number is a 64-bit floating-point value with 53 bits of precision. Every integer up to 9,007,199,254,740,991 (253 − 1, Number.MAX_SAFE_INTEGER) is exact; above that, numbers are rounded to the nearest value the format can hold. That matters for 64-bit IDs, database keys, hashes and memory addresses.
Try it in a browser console: parseInt("FFFFFFFFFFFFFFFF", 16) prints 18446744073709552000, but the true value of 264 − 1 is 18,446,744,073,709,551,615. A converter built on parseInt gives you the first number. This one gives you the second, because BigInt("0xFFFFFFFFFFFFFFFF") keeps every digit. Epoch values are a smaller version of the same issue: the Unix timestamp converter handles milliseconds safely because current millisecond values sit between 240 and 241, well inside the safe range.
Text to ASCII Codes and Back
Every character has a number. In ASCII, A is 65 (hex 41) and a is 97 (hex 61) — exactly 32 apart, which is one bit (0x20) — and the digit 0 is 48 (hex 30). The second card above turns text into its codes in decimal, hex, binary and octal, and turns a list of codes back into text. Codes can be separated by spaces or commas.
| Character | Decimal | Hex | Binary | Octal |
|---|---|---|---|---|
| 0 | 48 | 30 | 00110000 | 060 |
| 9 | 57 | 39 | 00111001 | 071 |
| A | 65 | 41 | 01000001 | 101 |
| Z | 90 | 5A | 01011010 | 132 |
| a | 97 | 61 | 01100001 | 141 |
| z | 122 | 7A | 01111010 | 172 |
| (space) | 32 | 20 | 00100000 | 040 |
| ! | 33 | 21 | 00100001 | 041 |
| @ | 64 | 40 | 01000000 | 100 |
| ~ | 126 | 7E | 01111110 | 176 |
ASCII stops at 127. For anything beyond it the tool shows the Unicode code point: é is 233 (hex E9). That is not the same as its bytes on disk — in UTF-8, é is stored as two bytes, C3 A9. If you need bytes, or the full ASCII table, the binary translator has both; if you need those bytes as text-safe characters, the Base64 encoder is the next step.
Common Mistakes When Converting Number Bases
- Reading hex as decimal.
10in hex is sixteen, not ten, and100in hex is 256. Write the prefix (0x10) whenever the base is not obvious. - Grouping binary from the left. Always group bits into fours (for hex) or threes (for octal) from the right.
101101is2D, notB4. - Trusting
parseIntwith bad input.parseInt("12G", 16)returns18— it stops at the first invalid character and keeps what it has. This converter rejects the whole value instead and tells you "G" is not a hex digit. - Leading zeros meaning octal. In older C and JavaScript code,
0755is an octal literal. In modern JavaScript strict mode it is a syntax error, andparseInt("0755")returns 755 in decimal. Use0o755to be explicit. - Losing precision above 253. Converting 64-bit values through a floating-point number silently changes the last digits, as shown above.
- Mixing a minus sign with two's complement.
-FFandFF01(16-bit) both mean −255, but in different notations. Pick one: a sign for mathematics, a fixed-width pattern for what the machine stores.
How to Convert Number Bases in Code
JavaScript. toString(radix) formats and parseInt(text, radix) parses, for any base from 2 to 36. Use BigInt for anything above 253 − 1, and BigInt.asIntN / asUintN for two's complement.
(255).toString(16) // "ff"
(255).toString(2) // "11111111"
(5).toString(2).padStart(8, "0") // "00000101"
parseInt("1A", 16) // 26
BigInt("0xFFFFFFFFFFFFFFFF") // 18446744073709551615n
BigInt.asIntN(8, 255n) // -1n (0xFF as signed 8-bit)
BigInt.asUintN(8, -1n) // 255n
Python. Integers have arbitrary precision, so large values are exact by default. int() parses any base and accepts the matching prefix.
int("ff", 16) # 255
int("0xff", 16) # 255
int("101101", 2) # 45
hex(255) # '0xff'
bin(5) # '0b101'
oct(493) # '0o755'
format(255, "08b") # '11111111'
format(255, "X") # 'FF'
(-1) & 0xFF # 255 (two's complement byte)
C. printf formats hex and octal; strtol and strtoull parse them. There is no standard binary format specifier before C23.
printf("%x %X %o %08x\n", 255, 255, 493, 255); // ff FF 755 000000ff
long n = strtol("ff", NULL, 16); // 255
unsigned long long u = strtoull("FFFFFFFFFFFFFFFF", NULL, 16); // 18446744073709551615
Frequently Asked Questions
2F: 2×16 + 15×1 = 47. Or type the value into the hex field of this converter and read the decimal field.101101 in binary. The converter shows these steps for small values.F is 15, so FF is 15×16 + 15 = 255. In binary it is eight ones, 11111111, the largest value one byte can hold.0x marks a number as hexadecimal in C, JavaScript, Python and most other languages, so 0x10 is sixteen. 0b marks binary and 0o marks octal. This converter accepts each prefix in its own field, but you can leave it out.-FF), or as a two's complement bit pattern of a fixed width, which is how computers store them: −1 is FF in 8 bits and FFFFFFFF in 32 bits. Tick Two's complement and choose a width to convert between the two.FFFFFFFFFFFFFFFF is 18,446,744,073,709,551,615, but parseInt returns 18446744073709552000. This converter uses BigInt, so every digit is exact.73 and ZZ is 1,295. Choose any base from 2 to 36 in the "Any base" field.