About the Hex Calculator
Programmers meet hexadecimal in memory addresses, color codes, byte values and error codes. This hex calculator does exact arithmetic on hex numbers of any length, so FF + 1 = 100, which is 255 + 1 = 256 in decimal, and it supports bitwise AND, OR and XOR. Every result is shown in decimal and binary too, which makes debugging and learning easier.
Hex arithmetic works like decimal with a carry at 16 instead of 10. 9 + 1 = A, F + 1 = 10, and F + F = 1E, which is 15 + 15 = 30 in decimal. Multiplication and long division follow the familiar methods with base-16 digit tables. Because one hex digit maps to four bits, bitwise operations are easy to read in hex: 0xFF is the low eight bits all set, and AND with 0xFF keeps just the lowest byte of a value.
Example: 1A3F + FF = 1B3E, which in decimal is 6,719 + 255 = 6,974. 1A3F − FF = 1940, 1A3F × FF = 1A24C1 (1,713,345) and 1A3F ÷ FF = 1A remainder 59, that is 26 remainder 89. Bitwise, 1A3F AND FF = 3F keeps the low byte, 1A3F OR FF = 1AFF sets it, and 1A3F XOR FF = 1AC0 flips it.
For conversions only, use the hex to decimal converter and decimal to hex converter. Binary arithmetic is on the binary calculator, and hex color codes can be converted with the hex to RGB converter.
How to use the Hex Calculator
- Enter the first hex numberType digits 0–9 and A–F; an optional 0x prefix is fine.
- Choose an operationAdd, subtract, multiply, divide, AND, OR or XOR.
- Enter the second hex numberType the second value in hexadecimal.
- Read the resultSee the answer in hex, decimal and binary, with a decimal check.
Hex Calculator features
- Hex addition, subtraction, multiplication and division
- Bitwise AND, OR and XOR
- Exact for numbers of any length
- Quotient and remainder for division
- Decimal and binary equivalents
- Accepts 0x prefixes and lowercase
- Decimal check of every operation
Common uses
- Memory address and offset calculations
- Working with bytes, masks and flags
- Checking color code arithmetic
- Computer science homework
- Reverse engineering and debugging
Hexadecimal in practice: colours, addresses, error codes and hashes
Hexadecimal, base 16, uses the digits 0 to 9 and the letters A to F. It is the preferred way to write binary data for people, because each hex digit stands for exactly four bits. You meet hex in web colour codes, memory and network addresses, Unicode characters, error messages and file hashes. This guide shows those uses, how hex arithmetic carries at 16, and worked examples with colours and memory offsets.
Why hex suits computers
A byte of 8 bits can be written as exactly two hex digits, from 00 to FF, which is far more compact and readable than eight binary digits. Converting between hex and binary is simple because each hex digit maps to four bits: F is 1111, A is 1010 and 3 is 0011. Programmers therefore read hex almost as easily as binary, without the long strings of ones and zeros.
Colour codes
Web colours are written as six hex digits, two each for red, green and blue. In #FF5733, FF is 255 red, 57 is 87 green and 33 is 51 blue, giving a bright orange-red. Pure black is #000000, white is #FFFFFF, and greys have equal values for all three channels, such as #808080.
A worked example: lightening a colour
A designer wants a slightly lighter version of #3366CC. Adding #111111 to each channel gives 33 + 11 = 44, 66 + 11 = 77 and CC + 11 = DD, so the new colour is #4477DD. Each channel rose by 17 in decimal, enough for a visible but gentle lightening.
Adding too much would push a channel past FF, which cannot be stored in two digits; colour tools cap channels at FF instead of letting them overflow.
Memory addresses and offsets
Programmers and engineers write memory addresses and offsets in hex, often with the prefix 0x. Adding an offset of 0x2C to an address of 0x1F4 gives 0x220. In decimal, that is 500 + 44 = 544, but working directly in hex keeps addresses aligned with the hardware's view of memory, where boundaries often fall on round hex values.
Network addresses
Device hardware addresses, called MAC addresses, are 48-bit numbers written as six pairs of hex digits, such as 3C:22:FB:9A:10:7E. IPv6 internet addresses are 128 bits long and written as eight groups of four hex digits, with shortcuts for groups of zeros. Hex keeps these long numbers manageable for network administrators.
Unicode and error codes
Every character in Unicode has a code point written in hex, such as U+0041 for the letter A and U+1F600 for a grinning face emoji. Operating systems report errors in hex too: Windows error 0x80070005, for example, indicates that access was denied. Searching for the hex code usually finds documentation about the problem.
Hashes and checksums
File hashes, such as SHA-256, are long binary values usually shown in hex. A SHA-256 hash is 64 hex characters, each representing 4 bits, for 256 bits in total. Comparing a downloaded file's hash with the one published by the source confirms that the file has not been corrupted or altered.
Hex arithmetic
Hex addition works like decimal addition, but carries happen at 16 instead of 10. In hex, 9 + 7 = 10, because 16 in decimal is written 10 in hex, and F + 1 = 10 as well. Subtraction borrows 16 instead of 10. Once you remember that A to F stand for 10 to 15, the rules are the same as at school.
Common mistakes
- Treating hex digits A to F as letters rather than values 10 to 15.
- Carrying at 10 instead of 16.
- Confusing hex and decimal values without a prefix such as 0x.
- Letting colour channels overflow beyond FF.
Related tools
For base conversions, use Number Base Converter. For binary arithmetic, try Binary Calculator, and for colours, HEX to RGB Converter.
Hex in web addresses
Web addresses use hex to encode characters that are not allowed directly in a URL. A space becomes %20, because 20 is the hex code for a space, and an ampersand becomes %26. Seeing these codes in a link tells you which characters were encoded, and a URL decoder turns them back into readable text.
File signatures
Many file types begin with a recognisable sequence of bytes, often shown in hex. PDF files begin with 25 50 44 46, the hex codes for the characters %PDF, and PNG images begin with 89 50 4E 47. Programs read these signatures, sometimes called magic numbers, to identify a file's real type regardless of its name, which is also how security tools spot files disguised with the wrong extension.
Converting hex in your head
To convert a two-digit hex number to decimal, multiply the first digit by 16 and add the second. For C8, C is 12, so 12 × 16 + 8 = 200. For colour codes, this tells you how strong each channel is on the 0 to 255 scale, which is often all you need to adjust a colour by eye.
Limits
Arithmetic is exact for whole numbers; results are shown in hex, decimal and binary.
Frequently asked questions
How do I add hexadecimal numbers?
Add digit by digit from the right, carrying 1 whenever a column reaches 16. For 1A3F + FF: F + F = 1E (write E, carry 1), 3 + F + 1 = 13 (write 3, carry 1), then A + 1 = B, giving 1B3E.
What are the hex digits A to F?
They stand for ten to fifteen: A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15. With 0 to 9 they make sixteen digits, so 10 in hex means sixteen.
How do I convert hex to decimal?
Multiply each digit by a power of 16, starting from 1 on the right, and add. 1A3F = 1 × 4096 + 10 × 256 + 3 × 16 + 15 = 6,719. The calculator shows the decimal value of every result.
Why do programmers use hexadecimal?
Each hex digit is exactly four bits, so two hex digits describe one byte. Long binary values become short and readable, such as 0xFF instead of 11111111, while converting between the two stays trivial.
How do I subtract hex numbers?
Subtract column by column, borrowing 16 instead of 10 when the top digit is smaller. 1A3F − FF = 1940. If the second number is larger, the result is negative and shown with a minus sign.
What does 0x mean?
It is a prefix used by C, JavaScript, Python and many other languages to mark a number as hexadecimal, so 0x1A3F is the hex number 1A3F. The calculator accepts it, but it is optional.
What does AND with 0xFF do?
It keeps only the lowest eight bits, the last byte, and clears everything else. 0x1A3F AND 0xFF = 0x3F. Masks like this are common when packing or unpacking bytes from larger values.
How do I convert decimal to hex?
Divide the number by 16 repeatedly and write down the remainders from last to first, using A to F for 10 to 15. 6,974 ÷ 16 = 435 remainder 14 (E), and continuing gives 1B3E.