Xerobit

Hex Calculator: Hexadecimal Arithmetic and Bitwise Math

Enter two hexadecimal values and pick an operation to get the result instantly. This hex calculator handles addition, subtraction, multiplication, division and all standard bitwise operators, showing both hex and decimal output. It runs entirely in your browser so nothing is uploaded.

Result

  • Expression
    1A + 5
  • Hex result
    1F
  • Decimal result
    31
  • First value (dec)
    26
  • Second value (dec)
    5

How to use the hex calculator

  1. Type a hexadecimal number into the First value field. You may include a 0x prefix or leave it off.
  2. Select an operation from the dropdown: arithmetic (add, subtract, multiply, divide) or bitwise (AND, OR, XOR, shifts).
  3. Type the second hexadecimal number into the Second value field.
  4. The hex calculator updates live, displaying the result in both hexadecimal and decimal notation.

How hexadecimal arithmetic works

Hexadecimal is base 16, using digits 0 through 9 and letters A through F (representing 10 through 15). Each position is a power of 16 rather than 10. For example, the hex value 1A equals 1 times 16 plus 10, which is 26 in decimal.

When you perform hex addition such as 1A + 5, the calculator converts both operands to their numeric values (26 and 5), adds them to get 31, and then converts back to hex: 31 divided by 16 is 1 remainder 15, giving 1F. The same convert-compute-convert cycle applies to hex subtraction, multiplication and division.

Common hex values reference

This table lists frequently used hexadecimal numbers alongside their decimal equivalents. It is handy when working with color codes, memory addresses or bitmasks.

HexDecimalNotes
00Zero
F15Maximum single hex digit
1016One full base unit
7F127Max signed 8-bit integer
80128High bit set in a byte
FF255Max unsigned 8-bit integer
10025628
FFFF65,535Max unsigned 16-bit integer
FFFFFF16,777,215Max 24-bit color value

Bitwise operations explained

Bitwise operators work on each binary digit independently. The hexadecimal calculator supports AND (&), OR (|), XOR (^), left shift (<<) and right shift (>>).

For instance, F0 & 3C: F0 is 11110000 in binary and 3C is 00111100. AND keeps only bits that are 1 in both operands, yielding 00110000, which is 30 in hex (48 in decimal).

Shifts move bits left or right. 1 << 4 moves the single set bit four places to the left, producing 10000 in binary, or 10 in hex (16 in decimal). Left shifting by n positions multiplies the value by 2n; right shifting divides by 2n and truncates toward zero.

Practical uses for a hexadecimal calculator

Hexadecimal notation appears throughout computing because each hex digit maps exactly to four binary bits, making it far more compact than raw binary while remaining easy to convert.

  • CSS colors: Web colors use six hex digits (e.g., #FF5733). Adding or blending channels requires hex arithmetic.
  • Memory addresses: Debuggers display pointers in hex. Calculating offsets between addresses means performing hex addition or hex subtraction.
  • Permissions and flags: Unix file modes and feature flags are often combined with bitwise OR and masked with bitwise AND.
  • Networking: Subnet masks and IPv6 segments are written in hex. Tools like the subnet calculator rely on these representations internally.

For conversions between bases rather than arithmetic, see the number base converter.

Edge cases and common mistakes

A few pitfalls come up regularly when working with hex math:

  • Confusing hex with decimal: Entering 10 means sixteen, not ten. Always verify the base before calculating.
  • Negative results: Hex subtraction can produce negative values. This tool represents them with a leading minus sign followed by the magnitude in hex (e.g., -A for negative ten).
  • Division truncation: Integer division discards remainders. 5 / 2 yields 2, not 2.5.
  • Large inputs: JavaScript bitwise operators coerce operands to 32-bit signed integers. Values above 7FFFFFFF (2,147,483,647) will wrap around during bitwise operations. Arithmetic operations support larger magnitudes safely.
  • Invalid characters: Only digits 0-9 and letters A-F are valid. Characters like G, Z or spaces will cause an error.

Worked examples

Each result below was produced by the same code the tool runs, so you can check your own numbers against them.

ExampleInputResult
Hex additionFirst value (hex): 1A; Operation: +; Second value (hex): 5Expression: 1A + 5; Hex result: 1F; Decimal result: 31; First value (dec): 26; Second value (dec): 5
Hex subtractionFirst value (hex): FF; Operation: -; Second value (hex): 10Expression: FF - 10; Hex result: EF; Decimal result: 239; First value (dec): 255; Second value (dec): 16
Bitwise ANDFirst value (hex): F0; Operation: &; Second value (hex): 3CExpression: F0 & 3C; Hex result: 30; Decimal result: 48; First value (dec): 240; Second value (dec): 60
Left shiftFirst value (hex): 1; Operation: <<; Second value (hex): 4Expression: 1 << 4; Hex result: 10; Decimal result: 16; First value (dec): 1; Second value (dec): 4

FAQ

What is a hex calculator?

A hex calculator performs mathematical and bitwise operations directly on hexadecimal (base 16) numbers. It saves you from manually converting to decimal, computing, and converting back.

Do I need to type the 0x prefix?

No. The hexadecimal calculator accepts values with or without the 0x prefix. Both 1A and 0x1A are parsed as the same number.

Can I do hex addition with negative numbers?

Yes. Prefix a value with a minus sign, such as -A. The tool treats it as negative ten in decimal and computes accordingly.

Why does my bitwise result look wrong for large hex values?

JavaScript bitwise operators work on 32-bit signed integers. If either operand exceeds 7FFFFFFF in hex, the bits wrap around. Use smaller values for bitwise work or account for the 32-bit limit.

Is division exact?

Division uses integer truncation, meaning any fractional part is discarded. For example, 7 divided by 2 gives 3, not 3.5.

Are letters case-sensitive?

No. You can enter uppercase or lowercase hex digits. Both ff and FF represent 255.

Does this tool send my data anywhere?

No. All calculations happen locally in your browser. Nothing is transmitted over the network.