Hex Calculator
0x1F + 0x0A = 0x29, which is 41 in decimal. That is the kind of quick check this hex calculator is built for. Enter two hexadecimal values, choose add, subtract, multiply, or divide, and the tool returns both the hex result and the decimal interpretation of each input. It is useful when you are working with byte values, memory offsets, masks, color channels, packet fields, or homework problems and want a fast answer without mentally converting every step. This version stays narrow on purpose. It handles whole-number hex arithmetic, accepts values with or without a 0x prefix, and shows division as an integer quotient.
Quick answer
Hexadecimal is base 16, so each digit can be 0 through 9 or A through F, where A means 10 and F means 15.
What this tells you
- •Hexadecimal is base 16, so each digit can be 0 through 9 or A through F, where A means 10 and F means 15.
- •The calculator trims the input, removes one optional 0x prefix, and parses the remaining characters as a non-negative hex number.
- •It converts both hex inputs to decimal, performs the selected arithmetic operation, then converts the result back to uppercase hex.
- •The page shows the decimal value of A and B as well as the final result, which makes it easier to sanity-check your work when you are learning or debugging.
- •Division in this tool returns the integer quotient only. If 0x7B is divided by 0x10, the decimal math is 123 divided by 16, which becomes 7, not 7.6875.
- •Positive results print in full, with no 32-bit ceiling. A negative result that fits in a signed 32-bit integer prints as its 32-bit two's-complement pattern, so subtraction that goes below zero can produce a large wraparound-looking hex result even though the decimal result is negative.
How to Use
- 1Enter Hex A and Hex B using digits 0 through 9 and letters A through F. You can type uppercase or lowercase.
- 2Include the 0x prefix if you like, or leave it off. Both 1f and 0x1F are accepted.
- 3Choose the operation. Add and subtract are common for offsets and counters. Multiply is useful for block sizing. Divide is useful for quick quotient checks.
- 4Click calculate and read both outputs together. The hex result answers the base-16 question, while the decimal lines let you verify that the parser read your inputs the way you expected.
- 5For division, remember that this calculator gives the whole-number quotient only. If you need the remainder, use a remainder or long-division tool instead.
- 6If a result looks strange after subtraction, check the decimal line first. A negative decimal result can still appear as a large unsigned hex value because of how this tool formats hex output.
- 7Keep the inputs plain. Spaces inside the number, commas, signs, and separators are not supported here.
How It Works
Formula
decimalA = parseInt(hexA, 16)
decimalB = parseInt(hexB, 16)
resultDecimal = operation(decimalA, decimalB)
for divide: resultDecimal = floor(decimalA / decimalB)
r = resultDecimal, hex(n) = n.toString(16) in uppercase
r >= 0: resultHex = 0x + hex(r)
-2^31 <= r < 0: resultHex = 0x + hex(unsigned32(r))
r < -2^31: resultHex = -0x + hex(abs(r))The calculator first strips one optional 0x prefix and validates that the rest of each input contains only hex digits. It then converts both values to decimal and runs the selected operation on whole numbers. Addition, subtraction, and multiplication behave the way you would expect from standard integer arithmetic. Division uses the integer quotient by applying floor to the decimal result, so any fractional part is discarded. After the decimal result is computed, the tool formats the hex output in uppercase. Zero and positive results print in full at any size. A negative result between -2,147,483,648 and -1 prints as its 32-bit two's-complement pattern, which is how that value would sit in a 32-bit register. A negative result below -2,147,483,648 has no 32-bit pattern, so it prints with a minus sign. That detail matters when the decimal answer is negative, because the decimal line and the hex line will no longer look like simple signed versions of each other.
Calculation note: values are processed in the order shown above, using the current input units.
Worked Examples
Register offset addition
0x1F is 31 in decimal and 0x0A is 10. Add them and you get 41, which is 0x29 in hex. This is a common quick-check case when you are stepping through offsets or summing byte values by hand.
Simple subtraction that stays positive
0x2C equals 44 and 0x10 equals 16. Subtracting gives 28, which converts back to 0x1C. This is the cleanest kind of subtraction to verify in the tool because both the decimal and hex outputs stay intuitive.
Block size multiplication
0x20 is 32 and 0x08 is 8. Multiplying them gives 256, which is 0x100 in hex. Results like this come up in memory sizing, page calculations, and repeated unit scaling where powers of two are common.
Integer division for page counts
0x7B is 123 decimal and 0x10 is 16 decimal. Dividing 123 by 16 gives 7.6875, but this tool keeps only the integer quotient. That is why the displayed answer is 7, or 0x7 in hex. It is useful when you only care how many full chunks fit.
Scenario: Dana finds the end of a firmware table
Dana is reading a firmware map. A configuration table starts at offset 0x1000 and is 0x3F8 bytes long, so the first byte after it is 0x1000 + 0x3F8 = 0x13F8, which the decimal line confirms as 4096 + 1016 = 5112. A second table is 0x3A8 bytes (936) and holds fixed 0x40-byte (64) records, so Dana divides and gets 0xE, or 14 full records. 936 divided by 64 is 14.625, and the tool drops the fraction, so the 40 leftover bytes are padding she needs to account for separately.
Hex, decimal, binary, and octal for the values you meet most often
The hex and decimal columns are what this calculator prints for each value (it does not zero-pad, so 15 shows as 0xF). Binary and octal come from the same base conversion the tool uses for hex.
| Hex (as shown) | Decimal | Binary | Octal | Where it shows up |
|---|---|---|---|---|
| 0xF | 15 | 1111 | 17 | Largest value in one hex digit, one nibble of all ones |
| 0x10 | 16 | 10000 | 20 | First carry into the second hex digit |
| 0x7F | 127 | 1111111 | 177 | Largest signed 8-bit value |
| 0x80 | 128 | 10000000 | 200 | Sign bit of a byte, lowest value that needs 8 bits |
| 0xFF | 255 | 11111111 | 377 | Largest unsigned byte, one color channel at full |
| 0x100 | 256 | 100000000 | 400 | First value that needs a second byte |
| 0x400 | 1024 | 10000000000 | 2000 | 1 KiB, a common page and block size |
| 0xFFFF | 65535 | 1111111111111111 | 177777 | Largest unsigned 16-bit value, highest TCP port |
| 0xFFFFFF | 16777215 | 111111111111111111111111 | 77777777 | 24-bit RGB white, #FFFFFF in CSS |
| 0x7FFFFFFF | 2147483647 | 1111111111111111111111111111111 | 17777777777 | Largest signed 32-bit value |
| 0xFFFFFFFF | 4294967295 | 11111111111111111111111111111111 | 37777777777 | Largest unsigned 32-bit value, also how this tool prints -1 |
| 0x100000000 | 4294967296 | 100000000000000000000000000000000 | 40000000000 | First value that needs 33 bits, what 0xFFFFFFFF + 0x1 prints |
Hex and decimal cells are the tool's own output. Binary and octal use the same conversion, Number.prototype.toString with a radix of 2 or 8, specified in ECMA-262 (section Number.prototype.toString, radix 2 through 36). Negative results that fit in a signed 32-bit integer print as 32-bit two's-complement patterns: 0x10 minus 0x20 prints decimal -16 and hex 0xFFFFFFF0, and 0x0 minus 0x80 prints -128 and 0xFFFFFF80. Below -2,147,483,648 the hex line uses a minus sign instead, so 0x0 minus 0x100000000 prints -0x100000000.
What this hex calculator assumes
This tool assumes both inputs are non-negative whole numbers written in hexadecimal. It is not a signed integer simulator, a floating-point calculator, or a bitwise operations playground. If you need left shifts, AND masks, two's-complement interpretation by bit width, or arbitrary-precision math, you need a different tool than this one.
The divide operation is deliberately simple. It answers the question, how many whole times does B fit into A, and it drops any remainder. That is a useful behavior for chunk counts, page counts, block alignment checks, and classroom examples. It is not the same thing as full fractional division, and it does not expose the remainder separately.
Hex is base 16, and its real convenience is that one hex digit is exactly 4 bits, a nibble, so two hex digits are always one byte. 0xFF is 11111111 in binary and 255 in decimal, and 0x7F drops only the top bit to give 01111111, or 127. Octal groups bits in threes instead, which is why 255 is 377 in octal and why file permissions like 755 read naturally in that base. Decimal has no clean relationship to bits at all, which is why 0x400 feels round to a programmer (1024, ten bits) and 1000 does not.
You will meet hex in a few fixed places. CSS colors use the #RRGGBB form defined in the CSS Color Module Level 4 (section 5.2), where each pair of hex digits is one channel from 00 to ff, so #FF8000 is red 255, green 128, blue 0, and #FFFFFF is 0xFFFFFF, decimal 16,777,215. Memory addresses, register offsets, and file offsets in a hex dump are written in hex because each pair maps to a byte. MAC addresses are six bytes shown as twelve hex digits. Unicode code points like U+00E9 and most hash digests are hex too. In every case the arithmetic is the same base-16 work this page does.
Parsing and formatting follow ECMA-262. The tool strips an optional 0x and calls parseInt with a radix of 16, then formats the result with Number.prototype.toString(16), which accepts any radix from 2 to 36. That method writes a negative number with a leading minus sign, not as two's complement, so for a negative result that fits in a signed 32-bit integer the tool first applies an unsigned 32-bit view. That is why 0x10 minus 0x20 shows decimal -16 but hex 0xFFFFFFF0: the hex line is the 32-bit two's-complement pattern of -16. The decimal result line is the safest place to confirm the signed outcome.
Positive results have no 32-bit ceiling. 0xFFFFFFFF + 0x1 prints decimal 4294967296 and hex 0x100000000, and 0x10000 times 0x10000 gives the same answer. A negative result below -2,147,483,648 has no 32-bit pattern, so the hex line writes it with a minus sign: 0x0 minus 0x100000000 prints decimal -4294967296 and hex -0x100000000. Separately, ECMA-262 defines Number values as IEEE 754 double-precision, and Number.MAX_SAFE_INTEGER is 2^53 minus 1, or 9,007,199,254,740,991. Above that, integers lose exactness before the operation runs. For bytes, words, pages, offsets, and homework values this calculator is fine. For 64-bit identifiers or strict overflow behavior, use a BigInt-aware workflow instead.
Common mistakes
- Typing characters outside 0 through 9 and A through F. A value like 0x1G is not valid hex.
- Assuming division returns a remainder or decimal fraction. This calculator only returns the integer quotient.
- Expecting negative subtraction results to display as signed hex. The decimal line can be negative while the hex line shows a 32-bit two's-complement pattern, such as 0xFFFFFFF0 for -16.
- Pasting values with spaces, underscores, commas, or sign characters. This parser accepts plain hex text and one optional 0x prefix only.
- Mixing up decimal and hex place values. 0x10 is sixteen, not ten.
- Using very large values and assuming JavaScript will keep every integer exact far beyond the safe range.
Embed this calculator on your site
Paste this code where you want the calculator to appear. It is responsive, mobile-friendly, resizes automatically, and is free to use as long as the credit line stays in place.
<script src="https://calctide.com/embed.js" data-tool="hex-calculator" async></script>
<p style="font-size:12px;margin:4px 0 0">Hex Calculator by <a href="https://calctide.com/tech/hex-calculator/">CalcTide</a></p>Preview the embed at /embed/hex-calculator/.