Hexadecimal arithmetic, bitwise operations and conversions between hex, decimal, binary and octal — with exact results at any size.
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.
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
Edit either side — the other updates automatically.
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.
| Hex | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| Binary | 0000 | 0001 | 0010 | 0011 | 0100 | 0101 | 0110 | 0111 | 1000 | 1001 | 1010 | 1011 | 1100 | 1101 | 1110 | 1111 |
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.
| Position | 16⁴ | 16³ | 16² | 16¹ | 16⁰ |
|---|---|---|---|---|---|
| Decimal value | 65,536 | 4,096 | 256 | 16 | 1 |
| Example: 1A2B | — | 1 | A (10) | 2 | B (11) |
| Contribution | — | 4,096 | 2,560 | 32 | 11 |
Adding those gives 4,096 + 2,560 + 32 + 11 = 6,699.
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.
| Operation | Rule | F0 op 3C | Typical use |
|---|---|---|---|
| AND (&) | 1 only where both bits are 1 | 30 | Masking — isolating a field |
| OR (|) | 1 where either bit is 1 | FC | Setting flags |
| XOR (^) | 1 where the bits differ | CC | Toggling, checksums |
| NOT (~) | Flips every bit | depends on bit width | Inverting a mask |
| Left shift (<<) | Multiplies by 2 per place | F0 << 4 = F00 | Building addresses |
| Right shift (>>) | Divides by 2 per place | F0 >> 4 = F | Extracting 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.
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 code | RGB | Colour | Notes |
|---|---|---|---|
| #000000 | 0, 0, 0 | Black | All channels off |
| #FFFFFF | 255, 255, 255 | White | All channels full |
| #FF0000 | 255, 0, 0 | Red | Red only |
| #00FF00 | 0, 255, 0 | Green | Green only |
| #0000FF | 0, 0, 255 | Blue | Blue only |
| #FFFF00 | 255, 255, 0 | Yellow | Red + green |
| #808080 | 128, 128, 128 | Grey | All channels half |
| #1a237e | 26, 35, 126 | Indigo | The 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.
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.
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.
| Format | Hex signature | ASCII | Offset |
|---|---|---|---|
| JPEG | FF D8 FF | — | 0 |
| PNG | 89 50 4E 47 0D 0A 1A 0A | .PNG.... | 0 |
| 25 50 44 46 | 0 | ||
| ZIP / DOCX / XLSX | 50 4B 03 04 | PK.. | 0 |
| GIF | 47 49 46 38 | GIF8 | 0 |
| Java class | CA FE BA BE | — | 0 |
| ELF executable | 7F 45 4C 46 | .ELF | 0 |
| RAR archive | 52 61 72 21 | Rar! | 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.
| Width | Hex digits | Bytes | Unsigned max | Example |
|---|---|---|---|---|
| 8-bit | 2 | 1 | FF (255) | A single byte or colour channel |
| 16-bit | 4 | 2 | FFFF (65,535) | Unicode BMP, TCP port |
| 32-bit | 8 | 4 | FFFFFFFF (4.29 billion) | IPv4 address, RGBA colour |
| 64-bit | 16 | 8 | FFFFFFFFFFFFFFFF | Memory 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.
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.
00000000 89 50 4E 47 0D 0A 1A 0A |.PNG....00000008 00 00 00 0D 49 48 44 52 |....IHDR00000010 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.
89 50 4E 47 is the PNG signature — 50 4E 47 spells "PNG" in ASCII, and the leading 89 is deliberately non-printable so text editors cannot corrupt the file.49 48 44 52 spells "IHDR", the image header chunk.00 00 01 00 is 256 in hex — this image is 256 pixels wide, then 256 tall.08 06 means 8 bits per channel with colour type 6, which is RGBA.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.
| Character | Decimal | Hex | Binary |
|---|---|---|---|
| A | 65 | 41 | 0100 0001 |
| Z | 90 | 5A | 0101 1010 |
| a | 97 | 61 | 0110 0001 |
| z | 122 | 7A | 0111 1010 |
| 0 | 48 | 30 | 0011 0000 |
| 9 | 57 | 39 | 0011 1001 |
| space | 32 | 20 | 0010 0000 |
| € | 8364 | U+20AC | 3 bytes in UTF-8 |
| 😀 | 128512 | U+1F600 | 4 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.
| Power | Decimal | Bits | Meaning |
|---|---|---|---|
| 16⁰ | 1 | — | Units place |
| 16¹ | 16 | 4 | One nibble |
| 16² | 256 | 8 | One byte's range |
| 16³ | 4,096 | 12 | — |
| 16⁴ | 65,536 | 16 | 16-bit range |
| 16⁶ | 16,777,216 | 24 | RGB colour count |
| 16⁸ | 4,294,967,296 | 32 | 32-bit range, IPv4 space |
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.
| Width | Unsigned range | Signed range | −1 appears as |
|---|---|---|---|
| 8-bit | 00 to FF (0–255) | −128 to 127 | FF |
| 16-bit | 0000 to FFFF | −32,768 to 32,767 | FFFF |
| 32-bit | 00000000 to FFFFFFFF | ±2.1 billion | FFFFFFFF |
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.
Every CSS colour is hex — two digits each for red, green and blue.
#FF5733Bit masks and flags are written in hex because digits align with nibbles.
flags & 0x0FMAC addresses and IPv6 are written entirely in hex.
00:1A:2B:3C:4D:5EHashes, keys and file signatures are all displayed as hex strings.
SHA-256 = 64 hex digitsMemory addresses and hex dumps are how you read raw memory.
0x7FFE0A3CRegister values and firmware images are specified in hex.
PORTB = 0xFFEvery code point is written in hex, as U+ followed by the digits.
U+1F600Model checksums and binary weight files are inspected as hex.
magic: 47 47 55 461) 255 2) FF 3) F 4) AF 5) 256
1) 1B2A 2) 30 3) 3,735,928,559 4) −1 5) Cyan (green + blue)
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.