
Hexadecimal calculator
Perform arithmetic and bitwise operations on hexadecimal numbers.
The result is shown in hexadecimal, decimal and binary. Arithmetic results exceeding the selected width are flagged.
Method and assumptions
Method version 1.0.0 · Updated
Calculate with hexadecimal numbers
Formula: Addition, subtraction, multiplication, integer division, and bitwise AND, OR and XOR.
Operands accept digits 0–9 and A–F, with or without 0x. Division is integer division and discards the remainder. The selected width applies to bitwise operations; arithmetic results may exceed it.
- left
- First hexadecimal operand
- operation
- Operation
- right
- Second hexadecimal operand
- width
- Width for bitwise operations
Each operand accepts 1 to 64 hexadecimal digits. Division returns a truncated integer quotient. Bitwise operations accept unsigned operands that fit the selected width (8, 16, 32 or 64 bits).
Calculate with code
These short examples use the same inputs and core calculation as this tool. Adapt validation and formatting to your application.
JavaScript
const result = BigInt('0x2A') + BigInt('0x18');
console.log('0x' + result.toString(16).toUpperCase()); // 0x42TypeScript
const result: bigint = BigInt('0x2A') + BigInt('0x18');
console.log(`0x${result.toString(16).toUpperCase()}`); // 0x42Python
result = int('2A', 16) + int('18', 16)
print(f'0x{result:X}') # 0x42Java
import java.math.BigInteger;
var result = new BigInteger("2A", 16).add(new BigInteger("18", 16));
System.out.println("0x" + result.toString(16).toUpperCase()); // 0x42C#
using System.Numerics;
var result = BigInteger.Parse("2A", System.Globalization.NumberStyles.HexNumber)
+ BigInteger.Parse("18", System.Globalization.NumberStyles.HexNumber);
Console.WriteLine($"0x{result:X}"); // 0x42More languages
C
#include <stdio.h>
#include <stdlib.h>
unsigned long result = strtoul("2A", NULL, 16) + strtoul("18", NULL, 16);
printf("0x%lX\n", result); // 0x42C++
#include <iomanip>
#include <iostream>
const auto result = std::stoull("2A", nullptr, 16) + std::stoull("18", nullptr, 16);
std::cout << "0x" << std::uppercase << std::hex << result << "\n"; // 0x42PHP
$result = hexdec('2A') + hexdec('18');
printf('0x%X\n', $result); // 0x42PowerShell
$result = [Convert]::ToInt64('2A', 16) + [Convert]::ToInt64('18', 16)
'0x{0:X}' -f $result # 0x42