Home/Math/Hex Calculator

Hex Calculator

Hexadecimal arithmetic, bitwise operations and conversions between hex, decimal, binary and octal — with exact results at any size.

Quick Answer: What Is Hexadecimal?

Hexadecimal is base 16, using the digits 0–9 then A–F for the values ten to fifteen. Each hex digit represents exactly four bits, so one byte is always two hex characters — which is why FF means 255 and #FF0000 means pure red. Enter one or two hex numbers below to add, subtract, multiply, divide, apply bitwise operations, or convert between bases.

Binary Calculator

Hex uses 0–9 and A–F. Case does not matter, and spaces or a 0x prefix are ignored, so ff, FF and 0xFF all work. Any other character is rejected rather than silently trimmed.

Keyboard: Enter calculates · Esc clears

RGB ↔ Hex colour converter

Edit either side — the other updates automatically.

Result
Hexadecimal sum
0x1B2A
6699 + 255 = 6954 in decimal
Why the input validation matters. Many hex tools parse with a function that stops at the first character it does not recognise. Type 1G and it silently returns 1 — the value of the leading digit — with no warning. This calculator rejects the input and names the offending character.

What Is Hexadecimal?

Hexadecimal, or hex, is the base-16 number system. Decimal needs ten digits and binary needs two; hex needs sixteen, so after 9 it borrows the letters A to F.

Hex0123456789ABCDEF
Decimal0123456789101112131415
Binary0000000100100011010001010110011110001001101010111100110111101111
value = … + d₂×16² + d₁×16¹ + d₀×16⁰
1A2B = 1×4096 + 10×256 + 2×16 + 11 = 6699

Why Computers Use Hexadecimal

Because 16 is 2⁴, one hex digit is exactly four bits — a nibble. Two hex digits make one byte, always. That clean mapping is the whole reason hex exists in computing: it compresses binary by a factor of four with no arithmetic, just substitution.

Compare writing a 32-bit value: 11011110101011011011111011101111 in binary, or DEADBEEF in hex. Both say the same thing, but only one can be read aloud or checked by eye.

Hexadecimal Place Values

Position16⁴16³16²16¹16⁰
Decimal value65,5364,096256161
Example: 1A2B1A (10)2B (11)
Contribution4,0962,5603211

Adding those gives 4,096 + 2,560 + 32 + 11 = 6,699.

Converting Between Bases

The four methods

Hex → decimal: multiply each digit by its place value and add.
Decimal → hex: divide by 16 repeatedly, reading remainders bottom to top.
Hex → binary: replace each digit with its 4-bit pattern.
Binary → hex: group into fours from the right, convert each group.

Hex FF to decimal

F = 15, so 15×16 + 15×1
240 + 15
= 255

Decimal 255 to hex

255 ÷ 16 = 15 remainder 15 (F)
15 ÷ 16 = 0 remainder 15 (F)
Read upward: FF

Hex 1A2B to binary — pure substitution

1 → 0001, A → 1010, 2 → 0010, B → 1011
= 0001 1010 0010 1011
No arithmetic needed, which is exactly why programmers use hex

Hexadecimal Arithmetic

Hex arithmetic works exactly like decimal, except you carry at 16 instead of 10. The only real difficulty is remembering that A–F are values, not labels.

Addition: 1A2B + FF

B + F = 11 + 15 = 26 = 1A, so write A and carry 1
2 + F + 1 = 18 = 12, so write 2 and carry 1
A + 1 = B, then 1
= 1B2A (6699 + 255 = 6954)

Multiplication: FF × 10

In hex, 10 means sixteen
255 × 16 = 4080
= FF0 — multiplying by 10 in hex just shifts one digit left

Bitwise Operations in Hex

OperationRuleF0 op 3CTypical use
AND (&)1 only where both bits are 130Masking — isolating a field
OR (|)1 where either bit is 1FCSetting flags
XOR (^)1 where the bits differCCToggling, checksums
NOT (~)Flips every bitdepends on bit widthInverting a mask
Left shift (<<)Multiplies by 2 per placeF0 << 4 = F00Building addresses
Right shift (>>)Divides by 2 per placeF0 >> 4 = FExtracting a nibble

Shifting by 4 moves exactly one hex digit. That makes hex ideal for bit manipulation: value >> 4 drops the last hex digit, and value & 0xF keeps only that digit.

NOT needs a bit width. Flipping every bit of 0F gives F0 in 8-bit but FFFFFF F0 in 32-bit, because the leading zeros flip too. This calculator asks which width you mean.

Hex in Web Colours

HTML and CSS colours are hex: two digits each for red, green and blue, giving 256 levels per channel and 16,777,216 combinations in total.

Hex codeRGBColourNotes
#0000000, 0, 0BlackAll channels off
#FFFFFF255, 255, 255WhiteAll channels full
#FF0000255, 0, 0RedRed only
#00FF000, 255, 0GreenGreen only
#0000FF0, 0, 255BlueBlue only
#FFFF00255, 255, 0YellowRed + green
#808080128, 128, 128GreyAll channels half
#1a237e26, 35, 126IndigoThe colour used on this page

The shorthand #F00 expands to #FF0000 by doubling each digit. An optional fourth pair sets transparency, so #FF000080 is red at about 50% opacity.

Hex in Networking and Memory

MAC addresses are six bytes written as twelve hex digits, usually grouped in pairs: 00:1A:2B:3C:4D:5E. The first three bytes identify the manufacturer.

IPv6 addresses are 128 bits written as eight groups of four hex digits, such as 2001:0db8:85a3:0000:0000:8a2e:0370:7334. Leading zeros can be dropped and one run of zero groups replaced by ::.

Memory addresses appear in hex in every debugger, because the digits align with the underlying bit fields. A 64-bit pointer is sixteen hex digits.

Magic numbers identify file types by their first bytes: FFD8FF starts a JPEG, 89504E47 a PNG, and 25504446 a PDF.

File Signatures (Magic Numbers)

Most file formats begin with a fixed sequence of bytes that identifies the type, regardless of the file extension. Security tools and file managers read these rather than trusting the name.

FormatHex signatureASCIIOffset
JPEGFF D8 FF0
PNG89 50 4E 47 0D 0A 1A 0A.PNG....0
PDF25 50 44 46%PDF0
ZIP / DOCX / XLSX50 4B 03 04PK..0
GIF47 49 46 38GIF80
Java classCA FE BA BE0
ELF executable7F 45 4C 46.ELF0
RAR archive52 61 72 21Rar!0

The PK in a ZIP signature comes from Phil Katz, who created the format — and because DOCX and XLSX files are ZIP archives underneath, they share it. Renaming a file changes nothing: the signature is what actually identifies it.

Hex Digits by Word Size

WidthHex digitsBytesUnsigned maxExample
8-bit21FF (255)A single byte or colour channel
16-bit42FFFF (65,535)Unicode BMP, TCP port
32-bit84FFFFFFFF (4.29 billion)IPv4 address, RGBA colour
64-bit168FFFFFFFFFFFFFFFFMemory pointer, large ID

The rule is simply bits ÷ 4, because each hex digit carries four bits. That is why a SHA-256 hash is 64 hex characters: 256 ÷ 4.

Reading a Hex Dump

A hex dump shows raw bytes in three columns: the address, the bytes themselves, and any printable characters. This is what a debugger or forensic tool displays.

A real dump — the start of a PNG file

00000000 89 50 4E 47 0D 0A 1A 0A |.PNG....
00000008 00 00 00 0D 49 48 44 52 |....IHDR
00000010 00 00 01 00 00 00 01 00 |........
00000018 08 06 00 00 00 5C 72 A8 |.....\r.

How to read it. The left column is the byte offset in hex, increasing by 8 each line. The middle is the byte values. The right shows those bytes as ASCII where printable, with a dot for anything else.

Every byte of every file can be read this way. Hex is the standard display format because two digits map cleanly to one byte, so the columns always line up.

ASCII and Unicode in Hex

CharacterDecimalHexBinary
A65410100 0001
Z905A0101 1010
a97610110 0001
z1227A0111 1010
048300011 0000
957390011 1001
space32200010 0000
8364U+20AC3 bytes in UTF-8
😀128512U+1F6004 bytes in UTF-8

Uppercase and lowercase differ by exactly 0x20, which is a single bit. That is why toggling bit 5 switches the case of any ASCII letter.

Powers of 16

PowerDecimalBitsMeaning
16⁰1Units place
16¹164One nibble
16²2568One byte's range
16³4,09612
16⁴65,5361616-bit range
16⁶16,777,21624RGB colour count
16⁸4,294,967,2963232-bit range, IPv4 space

Signed Values and Two's Complement

Hex has no minus sign, so negatives use two's complement just as binary does. In 8-bit, −1 is FF, −2 is FE and −128 is 80. Whether FF means 255 or −1 depends entirely on whether the value is being read as signed or unsigned — the bits are identical.

WidthUnsigned rangeSigned range−1 appears as
8-bit00 to FF (0–255)−128 to 127FF
16-bit0000 to FFFF−32,768 to 32,767FFFF
32-bit00000000 to FFFFFFFF±2.1 billionFFFFFFFF

Use the Programmer mode panel above to see any result at 8, 16, 32 or 64 bits, with its signed reading and an overflow warning where it does not fit.

Where Hexadecimal Is Used

Web Design

Every CSS colour is hex — two digits each for red, green and blue.

#FF5733

Programming

Bit masks and flags are written in hex because digits align with nibbles.

flags & 0x0F

Networking

MAC addresses and IPv6 are written entirely in hex.

00:1A:2B:3C:4D:5E

Cybersecurity

Hashes, keys and file signatures are all displayed as hex strings.

SHA-256 = 64 hex digits

Debugging

Memory addresses and hex dumps are how you read raw memory.

0x7FFE0A3C

Embedded Systems

Register values and firmware images are specified in hex.

PORTB = 0xFF

Unicode

Every code point is written in hex, as U+ followed by the digits.

U+1F600

Machine Learning

Model checksums and binary weight files are inspected as hex.

magic: 47 47 55 46

Common Mistakes

Watch out for these:
  • Reading hex as decimal. 10 in hex is sixteen, not ten.
  • Treating A–F as letters. They are digits worth 10 to 15.
  • Forgetting to carry at 16. In hex, 8 + 8 = 10, meaning sixteen.
  • Dropping the 0x prefix in code. Without it, most languages read the value as decimal.
  • Mixing up FF and 255 contexts. Same value, but FF as signed 8-bit means −1.
  • Assuming case matters. ff and FF are identical, though many style guides prefer uppercase.
  • Trusting a tool that trims bad input. If 1G returns an answer instead of an error, part of your number was discarded.

Practice Questions

Beginner (with answers)

  1. Convert FF to decimal.
  2. Convert 255 to hex.
  3. What is A + 5 in hex?
  4. Convert 1010 1111 binary to hex.
  5. How many values fit in two hex digits?
Show answers

1) 255   2) FF   3) F   4) AF   5) 256

Advanced (with answers)

  1. Calculate 1A2B + FF.
  2. Calculate F0 AND 3C.
  3. Convert DEADBEEF to decimal.
  4. What is FF in 8-bit signed?
  5. What colour is #00FFFF?
Show answers

1) 1B2A   2) 30   3) 3,735,928,559   4) −1   5) Cyan (green + blue)

Did you know? DEADBEEF is a real convention, not a joke. Programmers fill uninitialised memory with recognisable hex patterns so that a bug shows up obviously in a debugger. Other traditional markers include CAFEBABE, which begins every compiled Java class file, and BAADF00D.
Pro tip. To convert hex to binary, never do arithmetic — just substitute each digit for its four bits. Going the other way, group the bits into fours from the right.
Pro tip. Memorise a few anchors: 0x10 = 16, 0x20 = 32, 0x40 = 64, 0x80 = 128, 0xFF = 255. Most byte-level work sits between these.

🔑 Key Takeaways

  • Hex is base 16, using 0–9 then A–F for ten to fifteen
  • One hex digit is exactly four bits, so a byte is always two hex digits
  • Converting hex to binary is substitution, not arithmetic
  • Hex arithmetic carries at 16 rather than 10
  • Colours, MAC addresses, IPv6, hashes and memory addresses are all hex

Frequently Asked Questions

What is hexadecimal?

Hexadecimal is the base 16 number system. It uses the digits 0 to 9 and then the letters A to F for the values ten to fifteen, so FF means 255.

Why do computers use hexadecimal?

Because 16 is 2 to the power 4, one hex digit is exactly four bits. That makes hex a compact shorthand for binary, with two hex digits per byte and no arithmetic needed to convert.

What are the hexadecimal digits?

There are sixteen: 0 to 9 followed by A, B, C, D, E and F. A is ten, B is eleven, and so on up to F, which is fifteen.

How do you convert hex to decimal?

Multiply each digit by its place value, which is a power of 16, then add the results. For FF that is 15 times 16 plus 15, which is 255.

How do you convert decimal to hex?

Divide by 16 repeatedly and record each remainder, then read the remainders from bottom to top, writing 10 to 15 as A to F.

How do you convert hex to binary?

Replace each hex digit with its four bit pattern. A becomes 1010 and F becomes 1111, so AF becomes 1010 1111. No arithmetic is needed.

How do you convert binary to hex?

Group the bits into fours starting from the right, padding with leading zeros, then convert each group to a single hex digit.

How do you add hexadecimal numbers?

Add column by column as in decimal, but carry when a column reaches 16 rather than 10. So 8 plus 8 is 10 in hex, which means sixteen.

What is base 16?

Base 16 means each position is worth sixteen times the one to its right. The places are 1, 16, 256, 4096 and so on.

What is a nibble?

A nibble is four bits, which is exactly one hexadecimal digit. Two nibbles make one byte, which is why a byte is always two hex characters.

Why is FF equal to 255?

F is fifteen, so FF means fifteen times sixteen plus fifteen, which is 240 plus 15, or 255. That is the largest value one byte can hold.

What does the 0x prefix mean?

0x marks a number as hexadecimal in most programming languages. Without it, 10 would be read as ten rather than sixteen.

Does capitalisation matter in hex?

No. The value ff is identical to FF. Many style guides prefer uppercase for readability, but both are correct.

How are hex colours used in web design?

An HTML colour code gives two hex digits each for red, green and blue. FF0000 is pure red and FFFFFF is white, giving 16,777,216 possible colours.

What is a MAC address?

A MAC address identifies a network interface using six bytes, written as twelve hex digits in pairs, such as 00:1A:2B:3C:4D:5E.

Why is IPv6 written in hexadecimal?

An IPv6 address is 128 bits, which would be unreadable in binary and awkward in decimal. Eight groups of four hex digits keeps it manageable.

What are bitwise operations in hex?

They work on the underlying bits. AND keeps bits set in both values, OR sets bits present in either, and XOR sets bits that differ. Hex is convenient because shifting by four moves exactly one digit.

What is two's complement in hex?

It is how negative numbers are stored. In 8-bit, minus 1 is FF and minus 128 is 80. Whether FF means 255 or minus 1 depends on whether the value is read as signed or unsigned.

How is hexadecimal used in programming?

Programmers write bit masks, flags, memory addresses and colour values in hex because the digits line up with the underlying bits, making patterns easy to see.

How is hexadecimal used in cybersecurity?

Hashes, encryption keys, file signatures and memory dumps are all displayed as hex strings, because hex represents raw bytes compactly and unambiguously.

What does DEADBEEF mean?

It is a recognisable hex pattern that programmers write into unused memory so problems stand out in a debugger. CAFEBABE, which starts every Java class file, serves a similar purpose.

Is this Hex Calculator free?

Yes. It is free with no sign-up, works on any device, and runs entirely in your browser so your entries stay private.

References

Last updated: July 2026
Reviewed by Mohsin Iqbal. All arithmetic and bitwise operations use arbitrary-precision integers, so results stay exact well beyond the 32-bit and 53-bit limits that affect many browser-based binary tools. Input is validated character by character and rejected if it contains a non-binary digit, rather than being silently truncated. Operations that depend on word size, such as NOT and negative values, require you to choose a bit width. This page is for educational purposes.