Lelifi·tools

Hex Calculator

0x3B82F6 converts to 3,900,150 in decimal, with three bytes reading 3B, 82 and F6 in hex. Adding 0x2A and 0x15 gives 0x3F, which is 63. The calculator converts hex to decimal and binary and runs addition, subtraction, multiplication and division in base 16.

Paste a hex value with or without the 0x prefix. The result shows the decimal value, the binary groups, the byte split and the signed reading at three widths.

Arithmetic on two hex operands.

Convert a hex value to decimal and binary, see how it reads as a signed number at 8, 16 or 32 bits, and run arithmetic on two hex operands.

By the Lelifi editors ·

Key takeaways

Six hex digits, six place values: 0x3B82F6316^5 = 1,048,5763 x = 3,145,728B16^4 = 65,53611 x = 720,896816^3 = 4,0968 x = 32,768216^2 = 2562 x = 512F16^1 = 1615 x = 240616^0 = 16 x = 6Adding the six products gives 3,900,150, which is the decimal value of 0x3B82F6.
Each digit is multiplied by a power of sixteen. The six products sum to 3,900,150 for 0x3B82F6.
One byte, two readings: unsigned 0 to 255, signed -128 to 127negative as signedzero and positive0x80 = -1280x00 / 0xFF0x7F = 1270xA9 = -87Markers show where the byte 0xA9 lands: 169 read as unsigned, -87 read as signed.
The byte 0xA9 sits at 169 when read unsigned and at -87 when read signed, because the top bit carries a weight of -128.
On this page
  1. What a hex calculator does
  2. Place values: reading 0x3B82F6
  3. Hex arithmetic by hand
  4. The sixteen digits and their bits
  5. Fixed widths and two's complement
  6. Bytes, grouping and memory addresses
  7. Hex in color codes and text
  8. Mistakes that change the value

What a hex calculator does

Hexadecimal is base 16, so each digit holds one of sixteen values: 0 through 9, then A for ten through F for fifteen. A single hex digit covers exactly four bits, which is why computer documentation uses hex instead of binary: four hex digits describe a 16 bit word in a readable width.

The calculator does two jobs. In the top block it converts a hex value to decimal and binary and shows how the same byte pattern reads as a signed number. In the lower block it performs addition, subtraction, multiplication and division on two hex operands and returns the result in hex and decimal.

TermMeaningExample
Hex digit4 bits, values 0 to 15F is 15
Byte2 hex digits, 8 bits3B is 59
Word4 hex digits, 16 bits3B82 is 15,234
0x prefixMarks a number as hex in code and datasheets0x3B82F6

The 0x prefix is a convention from C and its descendants, not part of the number. Some tools write a trailing h instead, as in 3B82F6h, and CSS writes a leading hash, as in #3B82F6. All three describe the same six digits.

Place values: reading 0x3B82F6

Each position is a power of sixteen, starting at 1 on the right. Read the digits left to right and multiply each by its place value.

DigitDecimalPlace valueProduct
331,048,5763,145,728
B1165,536720,896
884,09632,768
22256512
F1516240
6616

The six products sum to 3,900,150. Working the additions in order: 3,145,728 + 720,896 = 3,866,624, then + 32,768 = 3,899,392, then + 512 = 3,899,904, then + 240 = 3,900,144, then + 6 = 3,900,150.

Two checks catch most mistakes. The digit count sets the range: six hex digits top out at 16,777,215, so a six digit result near 3.9 million is plausible. And the leading digit dominates: a leading 3 means the value is at least 3,145,728 and less than 4,194,304, so any answer outside that band has a place value wrong by a factor of sixteen.

Hex arithmetic by hand

Hex arithmetic follows the same carrying rules as decimal, with a carry at sixteen instead of ten. Converting both operands to decimal first is the reliable way to check a result.

OperationIn hexIn decimalResult
Addition2A + 1542 + 213F, which is 63
SubtractionA0 - 1B160 - 2785, which is 133
Multiplication1A x C26 x 12138, which is 312
DivisionFF / A255 / 1019 remainder 5

Addition first: A plus 5 is 10 plus 5, which is 15, written F. The 2 plus 1 makes 3, so the answer is 3F. If the units column had reached sixteen, the carry would add one to the sixteens column, which is exactly what happens in 0xFF + 0x01. F plus 1 is sixteen, so the units digit becomes 0 and one carries, and the whole answer is 0x100, or 256.

Subtraction borrows sixteen. In 0xA0 - 0x1B the units column needs 0 minus 11, so borrow one sixteen: 16 minus 11 is 5. The sixteens column then has 9 left after lending one, and 9 minus 1 is 8, giving 0x85. Multiplication is ordinary long multiplication with the hex digit table: 0x1A x 0x0C is 26 x 12 = 312, and 312 in hex is 0x138.

Division returns an integer quotient and a remainder. 0xFF / 0x0A is 255 / 10 = 25 with 5 left over, so 0x19 remainder 0x5. The calculator reports both parts because a remainder is usually the interesting half in bit manipulation.

The sixteen digits and their bits

Every hex digit maps to exactly four bits, which is the whole reason hex exists. The table below is worth memorizing for the first eight values and easy to derive for the rest.

HexDecimalBinaryHexDecimalBinary
000000881000
110001991001
220010A101010
330011B111011
440100C121100
550101D131101
660110E141110
770111F151111

The pattern is that the top bit of each nibble is worth 8, so 8 through F all start with a 1. That is also why a hex digit of 8 or above sets the high bit of its nibble, which matters when the nibble is the top of a signed byte.

Reading a byte as two digits is a direct split: 0x3B82F6 becomes 3B, 82 and F6. Each pair converts on its own, so 3B is 59, 82 is 130 and F6 is 246. A calculator that returns those three numbers is doing nothing beyond the digit table twice per byte.

Fixed widths and two's complement

A hex value has no sign built in. Whether 0xFF means 255 or -1 depends on the width the program uses and whether it treats the value as signed. Most computers store negative integers in two's complement, where the top bit carries a negative weight and the range splits in half.

WidthHexUnsignedSigned
8 bitFF255-1
8 bitA9169-87
8 bit80128-128
16 bitFFFF65,535-1
16 bit800032,768-32,768
32 bit800000002,147,483,648-2,147,483,648

The conversion rule for a signed value: if the top bit is set, subtract 2 to the power of the width. For 8 bits, 0xA9 is 169 unsigned, and 169 - 256 = -87. For 16 bits, 0xFFFF is 65,535, and 65,535 - 65,536 = -1. Purdue's course notes on bits show the same byte as -128 + 32 + 8 + 1 = -87, which is the bit-weight view of the same rule.

This is why a hex dump of a negative number looks enormous. Brown University's computer systems notes make the point directly: signed numbers appear as large hexadecimal values, and -1 in four bytes is 0xFFFFFFFF. Add 1 to that and every digit carries until the value wraps to zero, which is the property two's complement is built to have.

Width also decides overflow. A byte holding 0xFF plus 1 wraps to 0x00 and the carry disappears, so the answer is zero rather than 256. The calculator shows the arithmetic result at full precision and leaves the wrap to the width column, since guessing which width a program uses is not possible from the digits alone.

Bytes, grouping and memory addresses

Hex is used for memory because the grouping is honest. One byte is two digits, so a 32 bit address is eight digits and can be read in four byte pairs without any conversion.

Group from the right. When a value has an odd number of digits, pad a zero on the left before splitting. 0xF6A31 becomes 0F 6A 31, which is the byte order a dump would show. Splitting from the left instead gives F6 A3 1, which is wrong.

Endianness changes the print order, not the number. A little endian machine stores 0x3B82F6 as the bytes F6 82 3B in memory, while the value itself is still 0x3B82F6. A dump that reads 4 bytes as one integer will show a different hex string depending on the machine, which is why network protocols specify byte order explicitly.

Addresses step by width. Consecutive 4 byte integers in memory differ by 4, so addresses in a dump often end in 0, 4, 8 or C. Runs like 0x7FFE0A40, 0x7FFE0A44 and 0x7FFE0A48 are normal, not a rounding error.

The prefix is not part of the value. Pasting 0x7FFE0A40 into a tool that already expects hex gives an error or a wrong parse, because the x is not a digit. This calculator strips a leading 0x or # so either paste style works.

Hex in color codes and text

The most common place an ordinary user meets hex is a color code. A CSS color such as #3B82F6 packs three bytes in order: red 3B, green 82, blue F6. In decimal that is 59, 130 and 246.

CodeRedGreenBlue
#3B82F63B = 5982 = 130F6 = 246
#FFFFFFFF = 255FF = 255FF = 255
#FF0000FF = 25500 = 000 = 0

Eight digit codes add an alpha byte at the end, so #3B82F680 is the same blue at about 50 percent opacity. The hex to RGB converter covers that layout, the three digit shorthand and contrast checks; this page treats hex as a number system, which is why the arithmetic block has nothing to do with color.

Text encoding is the other everyday use. A Unicode code point is written U+1F600, and the digits after the plus are hex, so U+1F600 is 128,512 in decimal. A byte value in a document might be shown as 0xE9, which is 233 and, in Latin-1, the letter e with an acute accent. Reading it as a decimal 233 rather than a hex E9 is a common source of garbled text.

Mistakes that change the value

Five errors account for most wrong hex answers, and each has a visible symptom.

Reading 0x10 as ten. It is sixteen. The units digit is 0 and the sixteens digit is 1. The mistake is easy to make because 0x10 looks like the decimal number ten, and it shows up as an answer that is off by a factor of 1.6 at the first power and much more at higher ones.

Dropping a leading zero in a byte view. 0x0A is one byte holding ten. Written as 0xA it is the same number, but in a byte list the single digit shifts every following pair, so 0A 1B becomes A1 B, which is a different value entirely.

Mixing signed and unsigned. 0xFF is 255 or -1 depending on the width and the signedness. Adding 0xFF and 0x01 gives 0x100 in unsigned arithmetic and 0x00 inside a byte, and both are correct answers to different questions.

Forgetting that letters are digits. A calculator that only accepts 0 to 9 will reject C or F, and a hand calculation that treats B as eleven in one place and as a letter in another produces a total that is off by a small amount. The digit table above is the fix.

Assuming case matters. 0x3b82f6 and 0x3B82F6 are the same number. Case matters in text comparisons and in some hash formats, never in the value. A tool that rejects lowercase is being strict about notation, not about arithmetic.

One check catches nearly all of these: convert the result back to decimal by hand for the leading digit only. If the leading product does not match the size of the answer, the place value or the digit value is wrong.

Frequently asked questions

How do I convert hex to decimal?

Multiply each digit by its place value, which is a power of sixteen, then add. 0x3B82F6 is 3 x 1,048,576 plus 11 x 65,536 plus 8 x 4,096 plus 2 x 256 plus 15 x 16 plus 6, which totals 3,900,150.

What is 0xFF in decimal?

255. F is 15, so the value is 15 x 16 + 15 = 240 + 15 = 255.

Why is 0x10 not ten?

The 1 sits in the sixteens column and the 0 in the units column, so the value is 16. Ten in hex is 0x0A.

How do I add two hex numbers?

Add digit by digit and carry when a column reaches sixteen. 0x2A + 0x15 adds A and 5 to get F, then 2 and 1 to get 3, for 0x3F, which is 63 in decimal.

What is 0xFF plus 0x01?

0x100, or 256, at full width. Inside a single byte the carry is discarded and the result is 0x00, which is the wraparound that fixed width arithmetic produces.

How many bits are in one hex digit?

Four. That is why two hex digits make a byte, four make a 16 bit word and eight make a 32 bit value.

What does 0xFFFF mean as a signed number?

Minus 1 in 16 bit two's complement. Unsigned it is 65,535, and 65,535 - 65,536 = -1.

What is 0x8000 in decimal?

32,768 unsigned, and -32,768 signed in 16 bits. The top bit is set, so the signed reading subtracts 65,536.

How do I read 0xA9 as a signed byte?

169 unsigned, and 169 - 256 = -87 signed. The bit weights give the same answer: -128 + 32 + 8 + 1 = -87.

What is 0x1A times 0x0C?

0x138, which is 312. In decimal 26 x 12 = 312, and 312 is 1 x 256 + 3 x 16 + 8.

What is 255 divided by 10 in hex?

0x19 with a remainder of 0x5. 255 / 10 is 25 remainder 5, and 25 is 0x19.

Is hex case sensitive?

No. 0x3b82f6 and 0x3B82F6 are the same value. Case only matters in text comparisons, never in the number.

What is a hex color code?

Three bytes in order, red then green then blue. #3B82F6 is red 59, green 130 and blue 246, and an eight digit code adds an alpha byte at the end.

How do I convert hex to binary quickly?

Replace each hex digit with its four bit group from the digit table. 0x3B becomes 0011 1011, and the groups concatenate without any arithmetic.

Why does a hex dump show FFFFFFFF for minus one?

In 32 bit two's complement, -1 is all bits set, which is 0xFFFFFFFF. The value is the width of the storage, not an error.

Spotted a wrong number or a broken result?

More Math tools

See all Math tools

Fee schedules, rates and rules change without notice. Always confirm important figures with the official source before you rely on them.