Hex Calculator

It supports hex addition, subtraction, multiplication, division, hex to decimal, decimal to hex, and hex to binary conversions.

Hexadecimal Calculator

= ?

Hexadecimal to Decimal

Hexadecimal: = ?

Decimal to Hexadecimal

Decimal: = ?

Hexadecimal to Binary

Hexadecimal: = ?

Hex Bitwise Calculator

= ?
Bit width:

Hex, Decimal, and Binary Conversion Table

Hex is popular because each hexadecimal digit maps cleanly to 4 binary bits. That makes it much easier to read long binary values without losing the bit-level meaning.

Hex0123456789ABCDEF10
Decimal012345678910111213141516
Binary000000010010001101000101011001111000100110101011110011011110111110000

How Hex Arithmetic Works in Real Debugging

Hex math looks strange until you connect it to real work: memory addresses, color channels, register flags, packet bytes, checksums, file offsets, and firmware tables. The rules are the same as decimal arithmetic, but every column rolls over at 16 instead of 10.

Hex Addition: Adding Offsets Without Losing Your Place

Hex addition is what you use when a datasheet says a register block starts at 0x40000000 and the field you need is at offset 0x24. Add them and you get the final address: 0x40000024.

Work from right to left. If a column reaches 16 or more, carry 1 to the next hex column. For example: 0x9DA + 0xC12 = 0x15EC.

Hex addition example showing 9DA plus C12 equals 15EC

Hex Subtraction: Finding the Distance Between Two Addresses

Hex subtraction is useful when you want to know how far apart two addresses are. If a buffer starts at 0x20001000 and a pointer is currently at 0x20001238, the offset is 0x238.

Subtract from right to left. If the upper digit is smaller than the lower digit, borrow 1 from the next column. In hex, that borrowed 1 is worth 16 in the current column. For example: 0xC12 - 0x9DA = 0x238.

Hex subtraction example showing C12 minus 9DA equals 238

Hex Multiplication: Scaling Byte Counts and Data Blocks

Hex multiplication shows up when you calculate memory layouts. If each record is 0x20 bytes and you have 0x18 records, the total size is 0x300 bytes.

Multiply each digit like long multiplication, shift each partial product left by one hex position, then add the partial products. For example: 0x9DA × 0xC12 = 0x76E954.

Hex multiplication example showing 9DA times C12 equals 76E954

Hex Division: Splitting Address Ranges and Buffer Sizes

Hex division helps when you need to split a memory region into blocks. If a region has 0x1000 bytes and each block is 0x100 bytes, you have 0x10 blocks.

Divide the same way you would in decimal, but compare and subtract in base 16. For example: 0x9DAF8 ÷ 0xC1 = 0xD12 remainder 0x66.

Hex division example showing 9DAF8 divided by C1 equals D12 remainder 66

Real-world Use Cases for Hexadecimal in Programming

Hex is not just a number format from computer science class. It is the compact language developers use when values map directly to bytes, nibbles, flags, channels, addresses, and machine-level data.

Use Case 1: How to Add Hex Codes for Colors

Web colors use RGB hex format: #RRGGBB. Each color channel uses one byte, from 00 to FF. For example, white is #FFFFFF, blue is #0000FF, and yellow is #FFFF00.

A common color operation is channel subtraction. If you remove the blue channel from white, you get yellow:

#FFFFFF
- #0000FF
= #FFFF00

In RGB terms, that means:

ChannelCalculationResult
RedFF - 00FF
GreenFF - 00FF
BlueFF - FF00

This is why #FFFFFF - #0000FF = #FFFF00. If you are searching for how to add hex codes for colors, the key is to treat the color as three separate 8-bit channels, not one ordinary decimal number.

Use Case 2: Hex Address Calculation in Firmware

Embedded developers often read memory maps written entirely in hex. Suppose a peripheral base address is 0x40020000, and the register offset is 0x14. The register address is:

0x40020000 + 0x14 = 0x40020014

Now suppose an array of sensor records starts at 0x08004000. Each record is 0x20 bytes. To find record index 0x0A:

record_address = base + index × record_size
record_address = 0x08004000 + 0x0A × 0x20
record_address = 0x08004000 + 0x140
record_address = 0x08004140

This is the typical hex address calculation firmware workflow: base address, offset, stride, final address. It is simple, but getting one digit wrong can send your code to the wrong register or flash page.

Use Case 3: File Offsets and Binary Patching

Hex editors show file positions as hexadecimal offsets. If a structure starts at 0x1A0 and the field you want is 0x2C bytes into that structure, the field location is:

0x1A0 + 0x2C = 0x1CC

This kind of calculation is common when reading binary file formats, patching assets, checking packet dumps, or comparing two offsets in a debugger.

Use Case 4: Permissions, Flags, and Bit Masks

Many systems pack several on/off settings into a single number. For example, a permission byte might use one bit for read, one bit for write, and one bit for execute.

FlagBinaryHex
Read000000010x01
Write000000100x02
Execute000001000x04

To combine read and write permissions, use OR:

0x01 | 0x02 = 0x03

To check whether write permission is enabled, use AND:

0x03 & 0x02 = 0x02

Bitwise Operations for Hex Values

Regular arithmetic answers questions like "how much?" Bitwise operations answer questions like "which bits are on?" That is why programmers often need AND, OR, XOR, NOT, and shifts more than normal multiplication or division.

OperationUse it forExample
ANDCheck whether specific bits are enabled0xF0 & 0x0F = 0x00
ORTurn on specific bits0x80 | 0x01 = 0x81
XORToggle bits or compare differences0xAA ^ 0xFF = 0x55
NOTInvert bits within a fixed width~0x0F in 8-bit = 0xF0
Shift LeftMove bits left, often equivalent to multiplying by powers of 20x04 << 2 = 0x10
Shift RightMove bits right, often equivalent to dividing by powers of 20x80 >> 4 = 0x08

Hexadecimal to Decimal Conversion Formula

To convert hex to decimal, multiply each digit by its power of 16 and add the results.

Decimal value = Σ(hex digit × 16position)

Example:

CBA = C × 16² + B × 16¹ + A × 16⁰
CBA = 12 × 256 + 11 × 16 + 10
CBA = 3258
Hexadecimal to decimal conversion example showing CBA equals 3258

Decimal to Hexadecimal Conversion Method

Divide the decimal number by 16 repeatedly, keep each remainder, then read the remainders from bottom to top.

280 ÷ 16 = 17 remainder 8
17 ÷ 16 = 1 remainder 1
1 ÷ 16 = 0 remainder 1

280 decimal = 118 hex
Decimal to hexadecimal conversion example showing 280 decimal equals 118 hex

Hexadecimal to Binary Conversion

Each hex digit maps to 4 binary bits. That is why converting hex to binary is mostly a lookup operation.

A = 1010
1 = 0001
2 = 0010

A12 hex = 101000010010 binary
Hexadecimal to binary conversion example showing A12 equals 101000010010

Expert FAQ

Why does my hex subtraction look different with big-endian and little-endian data?

The arithmetic result does not change because of endian format. What changes is how bytes are ordered in memory. If you read the bytes in the wrong order, you are subtracting a different number.

For example, the two bytes 12 34 mean 0x1234 in big-endian, but 0x3412 in little-endian. If your subtraction result looks wrong, first confirm whether the byte sequence has been interpreted in the correct endian order.

How do I handle signed hex numbers and overflow?

Decide the bit width first. Hex values do not automatically tell you whether they are signed or unsigned. In an 8-bit signed value, 0xFF usually means -1 using two's complement. In an unsigned 8-bit value, 0xFF means 255.

Overflow also depends on width. For 8-bit arithmetic:

0xFF + 0x01 = 0x00 with carry out

The full mathematical result is 0x100, but an 8-bit register keeps only the lowest 8 bits, so the stored result becomes 0x00.

Why does NOT produce a huge value in some programming languages?

NOT needs a fixed bit width to be intuitive. In 8-bit arithmetic, ~0x0F = 0xF0. In 16-bit arithmetic, ~0x000F = 0xFFF0. In 32-bit arithmetic, ~0x0000000F = 0xFFFFFFF0.

If your language uses signed integers internally, the displayed result may look negative. Mask the result to the width you actually want:

result = (~value) & 0xFF

What is the safest way to compare two hex values from a debugger?

Normalize them first. Remove prefixes like 0x, confirm the width, confirm endian order, and decide whether the value is signed or unsigned. A lot of "wrong" hex math is really a parsing problem.

When should I use hex instead of decimal?

Use hex when the value maps naturally to bytes or bits: memory addresses, color codes, machine instructions, bit flags, Unicode code points, packet dumps, file offsets, and embedded registers. Use decimal when the value represents ordinary human-scale counting, such as prices, ages, distances, or quantities.

Long-tail Hex Calculator Topics

These examples are included because they match common developer searches and real debugging tasks:

  • how to add hex codes for colors: Treat RGB values as three separate channels, then add or subtract each channel.
  • hex address calculation firmware: Add base addresses, offsets, and structure sizes when working with memory maps.
  • hex memory offset calculator: Subtract two addresses to find the distance between them.
  • bitwise hex calculator for masks: Use AND, OR, XOR, and NOT to inspect or modify individual bits.
  • hex register value calculator: Combine register flags and decode embedded configuration values.
  • hex color subtraction calculator: Remove or compare RGB channels using hexadecimal arithmetic.

Hexadecimal Multiplication Table

x123456789ABCDEF10
1123456789ABCDEF10
22468ACE10121416181A1C1E20
3369CF1215181B1E2124272A2D30
448C1014181C2024282C3034383C40
55AF14191E23282D32373C41464B50
66C12181E242A30363C42484E545A60
77E151C232A31383F464D545B626970
88101820283038404850586068707880
99121B242D363F48515A636C757E8790
AA141E28323C46505A646E78828C96A0
BB16212C37424D58636E79848F9AA5B0
CC1824303C4854606C7884909CA8B4C0
DD1A2734414E5B6875828F9CA9B6C3D0
EE1C2A38465462707E8C9AA8B6C4D2E0
FF1E2D3C4B5A69788796A5B4C3D2E1F0
10102030405060708090A0B0C0D0E0F0100

Reference

Write Reply to This Calculator

Leave a Reply

Your email address will not be published. Required fields are marked *

^