Hex Converter

Hex converter: enter a value in hexadecimal, decimal, binary or octal and see it in all four, with the signed reading at 8 to 64 bits. Digits that form readable bytes also show as text. 255 is FF, 11111111 and 377. Runs in your browser.

One value, every base
0x, 0b, 0o prefixes, underscores and spaces are accepted. A minus sign is kept.
The same value in four bases
Hexadecimal48656C6C6F
Decimal310939249775
Binary100100001100101011011000110110001101111
Octal4414533066157
As textHello
Signed64-bit 310,939,249,775
Your input stays in this browser

Hex converter: one value in all four bases

Enter a number in any of hexadecimal, decimal, binary or octal and the converter shows it in the other three at once. A number is the same quantity whichever base writes it; only the digits change. 255 in decimal is FF in hex, 11111111 in binary and 377 in octal, and the tool shows all four together, with the signed reading at 8, 16, 32 and 64 bits underneath. A switch of the input base carries the value over, so you can step from one base to the next without retyping.

The same numbers in the four bases
DecimalHexadecimalBinaryOctal
10A101012
255FF11111111377
256100100000000400
1,0003E811111010001750
4,0961000100000000000010000
65,535FFFF1111111111111111177777

Spotting patterns saves time. Powers of two are a single 1 in binary and a 1, 2, 4 or 8 followed by zeros in hex: 256 is 100, 4,096 is 1000. A hex number of all F digits is one less than a power of 16, like 255 and 65,535. Octal and hex are both shorthand for binary, at three and four bits per digit.

Which converter fits the job

This page is the general-purpose one. When the question is a single direction, a dedicated page shows the working for that direction and explains the details that matter there.

General converter or a dedicated page
You wantUseWhy
A number in every baseThis converterAll four rows and the signed readings together
Hex to decimal with the digit-by-digit workingHex to decimalPlace values, signed 8 to 64 bit, code in four languages
Decimal to hex with the division stepsDecimal to hexRepeated division, negative numbers, padding
Hex to binary nibble by nibbleHex to binaryBit weights, masks, long values
Binary to hex by groupingBinary to hexPadding, sign extension, spaced input
Bytes that are textHex decoderCharacter encodings, error positions
Arithmetic on hex valuesHex calculatorAdd, subtract, multiply, divide, bitwise

Octal: the base the converter also covers

Octal uses the digits 0 to 7, and each digit is exactly three bits. It was convenient on machines with word sizes divisible by three, and it survives in Unix file permissions. The permission 755 is three octal digits, one for the owner, the group and everyone else, and each digit is three flags: read (4), write (2) and execute (1). 7 is 111, all three; 5 is 101, read and execute. The whole value 755 is 111101101 in nine bits, which reads rwxr-xr-x.

In decimal that number is 493 and in hex 1ED, which is why permissions are written in octal: the three-bit digits match the three flags. Octal also hides in source code. In C and in older JavaScript, a number written with a leading zero is read as octal, so 010 means 8 and no longer 10, a classic cause of bugs with zero-padded values. The 0o prefix, used by Python 3 and modern JavaScript, makes the base explicit.

Place values in each base

Every positional system works the same way: the rightmost digit counts ones, and each step left is worth the base times the previous place. Only the base differs. The diagram lays out the five lowest places for each of the four bases.

Place values in four basesThe five lowest place values: base 2: 1, 2, 4, 8, 16; base 8: 1, 8, 64, 512, 4096; base 10: 1, 10, 100, 1000, 10000; base 16: 1, 16, 256, 4096, 65536.position 4position 3position 2position 1onesbase 2168421base 84,0965126481base 1010,0001,000100101base 1665,5364,096256161
Each position is worth the base times the position to its right. The columns show positions 4 down to 0.

To convert by hand, multiply each digit by the place value in its own base and add; the result is the decimal number. To go the other way, divide by the new base and collect the remainders. The dedicated pages for hex to decimal and decimal to hex walk through both with examples.

When the hex is text instead of a number

The same digits can be a number or a message. Whether 48656C6C6F is the number 310,939,249,775 or the text Hello depends on where it came from. When the digits form whole bytes (an even count) whose values decode as readable UTF-8, the table gains an As text row that shows the reading, so you can see at a glance that a string looks like text. It is a hint about what the digits could mean, and the numeric rows hold the conversion: a short number like 4142 is also the letters AB.

For text, the hex decoder is the right tool, because it offers the character encodings (UTF-8, UTF-16, ASCII, Latin-1, Windows-1252) and reports invalid bytes. Going from text to hex has its own pages for text and ASCII. In other words, the converter here treats the input as one big number and the text tools treat it as a series of bytes.

Hex conversion in spreadsheets and calculators

Spreadsheets have conversion functions, with limits worth knowing before you rely on them. Excel's engineering functions include HEX2DEC, DEC2HEX, HEX2BIN, BIN2HEX, HEX2OCT and OCT2HEX, and Google Sheets provides the same names. Excel limits the input to 10 characters (40 bits) and treats the top bit as a sign, so FFFFFFFFFF returns −1 although its unsigned value is 1,099,511,627,775. DEC2HEX also rejects numbers outside the 40-bit range.

The Windows Calculator has a Programmer mode with HEX, DEC, OCT and BIN lines that update together, which is the same idea as this page, and macOS Calculator has a programmer view (Command+3). Both work on 64-bit integers, so values beyond 64 bits need a tool with arbitrary precision, such as this converter or Python.

Limits and precision

The failure that catches most people is silent precision loss. JavaScript represents every number as a 64-bit float with 53 bits of precision, so integers above 9,007,199,254,740,991 cannot all be represented, and a converter built on Number returns a rounded answer for a 16-digit hex value without any warning. Spreadsheets keep about 15 significant digits. Calculators with fixed word sizes wrap around instead: a 64-bit calculator turns 2^64 into 0.

This converter uses arbitrary-precision integers, so the answer is exact at any length, and it reports an invalid digit with its position instead of ignoring it. It does not do fractions: a hex number with a point is rejected. Floating-point hex is converted with hex to float, and hex colors with hex to RGB.

Base conversion in Python, JavaScript and the shell

Languages expose base conversion through two operations: parse a string in a base, and format an integer in a base.

Python
int("FF", 16)      # 255      int("377", 8)     # 255      int("11111111", 2)   # 255
format(255, "x")   # 'ff'     format(255, "o")  # '377'    format(255, "b")     # '11111111'
JavaScript
parseInt("FF", 16)   // 255
(255).toString(16)   // 'ff'      (255).toString(8)   // '377'      (255).toString(2)   // '11111111'
Shell and PowerShell
echo $((16#FF)) $((8#377)) $((2#11111111))     # 255 255 255
printf '%d %x %o\n' 255 255 255                # 255 ff 377

[Convert]::ToString(255, 16)   # ff       [Convert]::ToString(255, 8)   # 377       [Convert]::ToString(255, 2)   # 11111111

A worked example in every base: 4,096

Start with decimal 4,096. It is 2^12, so the binary form is a single 1 followed by twelve zeros: 1000000000000. Grouped in fours from the right that is 1 0000 0000 0000, which is 1000 in hex, a 1 and three zeros. Grouped in threes it is 1 000 000 000 000, which is 10000 in octal. By hand from decimal: 4,096 ÷ 16 = 256 remainder 0, 256 ÷ 16 = 16 remainder 0, 16 ÷ 16 = 1 remainder 0, 1 ÷ 16 = 0 remainder 1, which reads 1000 and agrees.

The example shows the connection between the bases. Hex and octal are both groupings of the binary digits, so converting between them never needs decimal. Decimal is the odd one out, because 10 is not a power of two, and every conversion that involves decimal needs division or multiplication. That is why the converter shows decimal as a result for orientation and treats the other three as a family.

Converting between hex and octal

To go from hex to octal, write each hex digit as four bits, regroup the bits in threes from the right, and read each group as an octal digit. The reverse writes each octal digit as three bits and regroups in fours. Take 2F3: 0010 1111 0011, regrouped as 001 011 110 011, is octal 1363. In decimal both are 755.

Hex to octal through binary
StepResult for 2F3
Hex digits2 F 3
Four bits each0010 1111 0011
Same bits in threes, from the right001 011 110 011
Octal digits1 3 6 3

The groups do not line up with each other, which is why hex and octal digits of the same number look unrelated. Octal is rarely needed today outside Unix permissions and some historical documentation, but the converter shows it in the same table so the three-bit and four-bit views can be compared.

Negative values and the signed readings

A minus sign in front of the input is kept in all four rows, so −FF is −255 in decimal, −11111111 in binary and −377 in octal. This is the mathematical negative of the number, and it is the right output for arithmetic. Registers and files store negative integers differently, as a two's complement bit pattern of a fixed width.

For positive input the converter goes the other way and lists what the same bits mean when read as signed integers of 8, 16, 32 and 64 bits, for every width that can hold the digits. The value 80 is 128 as an unsigned byte and −128 as a signed one; as a 16-bit value (0080) it is 128 either way. The full treatment, with the arithmetic of the sign bit, is on the hex to decimal page.

Hex in network addresses: IPv4, ports and masks

An IPv4 address is a 32-bit number written as four decimal bytes. As hex, 192.168.0.1 is C0 A8 00 01, or C0A80001, and the converter shows the decimal value of that number, 3,232,235,521. The reverse is how some tools print addresses: 7F000001 is 127.0.0.1, the loopback address. Subnet masks are easiest to read in binary: FFFFFF00 is 24 ones followed by eight zeros, hence /24.

Port numbers are 16-bit values and appear in hex in packet captures. Port 80 is 0050, 443 is 01BB and 8080 is 1F90. MAC addresses are six bytes of hex, which the converter treats as one 48-bit number if the colons are removed. The converter does not parse the dotted or colon-separated forms directly: remove the separators first, or convert each byte on its own line.

Other bases: base 32, base 36 and Base64

Bases above 16 need more digit symbols and are rare in numeric work. Base 36 uses 0 to 9 and A to Z, and is what JavaScript's (255).toString(36) produces (73) when a compact identifier is needed. Base 32 and Base 64 are different in kind: they are encodings that write bytes as text and were designed for transport, defined in RFC 4648. They do not interpret their input as one number, so their output is not a base conversion of its input's value.

This matters when comparing: the hex string FF is the number 255, while the Base64 string /w== is the single byte FF written in a Base64 alphabet. Converting between hex and Base64 therefore means converting the bytes, which the Base64 to hex converter does, rather than the numeric value.

Choosing the input base: what the converter does not guess

A string of digits has no base of its own. 12 is twelve in decimal, eighteen in hex, ten in octal and an error in binary. Converters that guess usually guess wrong for exactly the values that matter, so this one makes you choose: the input base selector decides how every digit is read. Prefixes agree with the choice and are optional (0x in hex mode, 0b in binary mode, 0o in octal mode); a prefix for a different base is reported as an invalid digit instead of being switched silently.

Each base has its own error message. A letter G in hex mode, an 8 or 9 in octal mode, and a 2 in binary mode are all named with their position in the input. If a pasted value fails, check the selector first: a decimal number copied from a spreadsheet and read as hex gives a plausible but wrong answer, since every decimal digit is also a valid hex digit, and the tool cannot tell the difference. That mistake produces no error at all, so look at the base before trusting a result.

Sizes and memory: hex values as kilobytes and megabytes

Memory sizes are powers of two, so in hex they are a 1, 2, 4 or 8 followed by zeros. A kibibyte is 0x400 bytes, which is 1,024, and each further factor of 1,024 adds three zeros to the hex number. Documents that give a memory map in hex are easier to read once these are familiar, and they explain why 0x1000 shows up as the page size.

Hex sizes and their names
HexBytesBinary unit
4001,0241 KiB
10004,0964 KiB, a memory page
1000065,53664 KiB
1000001,048,5761 MiB
100000016,777,21616 MiB
400000001,073,741,8241 GiB
1000000004,294,967,2964 GiB, the limit of a 32-bit address space

The binary units (KiB, MiB, GiB) are powers of 1,024 and differ from the decimal units that disk makers use (kB is 1,000 bytes). A 500 GB drive holds about 465 GiB, and the converter shows the exact byte counts when you need the difference: 500,000,000,000 bytes in hex is 746A528800.

Common hex values in binary and octal

The values people look up most have fixed binary and octal forms, and these are the ones the converter would show if you typed them. The decimal forms are on the hex to decimal page; this table covers the other two bases.

Frequently searched hex values in binary and octal
HexBinaryOctal
7F1111111177
8010000000200
FF11111111377
100100000000400
3FF11111111111777
FFF1111111111117777
7FFF11111111111111177777
FFFF1111111111111111177777

The pattern is regular for values of the form 2^n − 1, which are all ones in binary and, in octal, a leading digit followed by sevens: 7F is 177, FF is 377, 3FF is 1777, FFF is 7777. Octal and hex agree on the decimal value but not on how many digits it needs, because three bits and four bits rarely divide the same length.

Checking a large conversion

Convert the answer back. Typing the decimal result into the converter with the input base set to decimal should return the original hex, and a mismatch shows an input error such as a character dropped while copying. For large values, compare the number of digits: the decimal form of an n-digit hex number has between 1.2n − 1 and 1.2n digits, because each hex digit adds log10(16), about 1.204, decimal digits. A hex number of 16 digits cannot have fewer than 19 or more than 20 decimal digits.

Questions about the hex converter

What is a hex converter?

A tool that rewrites a number in another base. Hexadecimal is base 16, and a hex converter turns it into decimal (base 10), binary (base 2) or octal (base 8) and back. The same number is shown in all four so you can pick the one you need.

How do I convert hexadecimal to decimal with this converter?

Set the input base to hexadecimal, enter the value and read the decimal row. Prefixes such as 0x and underscores are ignored. For the digit-by-digit working, the hex to decimal page shows each step.

Does it convert hex to text?

When the hex digits form whole bytes of readable UTF-8 text, an As text row appears with the result, so 48656C6C6F shows Hello. A number such as 7B is also the character {, so the text row only tells you what the same digits would read as; the numeric rows are the converted value.

Why is there an octal row?

Octal is the third base used in computing. It still appears in Unix file permissions (755), in C escape sequences and in some older documentation. Each octal digit is three bits, so converting between octal and binary is as direct as hex and binary.

Is there a size limit?

The converter reads the input as an arbitrary-precision integer, so there is no fixed limit; very long inputs only take longer to display. It handles whole numbers. Fractions and floating-point values are converted on separate pages.