Perform hexadecimal arithmetic and convert between hex and decimal number systems.
Hex value:
8AB + B78
= 1423
Decimal value:
2219 + 2936
= 5155
Decimal value: 3501
Hexadecimal value: AA
Hexadecimal (or hex) is a base-16 numeral system that uses sixteen distinct symbols: 0-9 to represent values zero to nine, and A-F (or a-f) to represent values ten to fifteen. Each hex digit represents four binary digits (bits), making hex a compact way to express binary values in computing and digital electronics.
Hexadecimal is widely used by programmers and system designers because it provides a human-friendly representation of binary-coded values. One byte (8 bits) can be represented with just two hexadecimal digits, compared to eight binary digits.
| Hex | Decimal | Binary | Hex | Decimal | Binary |
|---|---|---|---|---|---|
| 0 | 0 | 0000 | 8 | 8 | 1000 |
| 1 | 1 | 0001 | 9 | 9 | 1001 |
| 2 | 2 | 0010 | A | 10 | 1010 |
| 3 | 3 | 0011 | B | 11 | 1011 |
| 4 | 4 | 0100 | C | 12 | 1100 |
| 5 | 5 | 0101 | D | 13 | 1101 |
| 6 | 6 | 0110 | E | 14 | 1110 |
| 7 | 7 | 0111 | F | 15 | 1111 |
Like decimal, hexadecimal is a positional numeral system. Each digit's place represents a power of 16, starting from 0 at the rightmost position.
Hex addition works similarly to decimal addition, but carries occur when the sum reaches 16 instead of 10. When a column sum exceeds 15 (F), carry 1 to the next higher column and keep the remainder.
Hex subtraction works like decimal subtraction. When borrowing in hex, you borrow 16 from the next higher digit, not 10 as in decimal.
Hex long multiplication follows the same structure as decimal long multiplication. Each digit in the second number is multiplied by the entire first number, shifted appropriately, and the intermediate results are summed using hex addition.
Hex division is analogous to decimal long division. The divisor is repeatedly subtracted from the dividend using hex subtraction, building the quotient digit by digit. Integer division returns the whole-number quotient.
Multiply each hex digit by 16 raised to its position power (starting from 0 on the right), then sum all products.
Repeatedly divide the decimal number by 16, recording the remainder each time. Continue until the quotient becomes zero. Read the remainders from last to first — this is the hex value. Remainders 10-15 become A-F.
Converting between binary and hex is extremely simple because each hex digit corresponds exactly to 4 bits.
1. Knuth, Donald E. "The Art of Computer Programming, Volume 2: Seminumerical Algorithms." Addison-Wesley. 1997.
2. Tanenbaum, Andrew S. "Structured Computer Organization." Pearson. 2012.
3. IEEE Standard for Floating-Point Arithmetic (IEEE 754). 2019.
4. Patterson, David A. and Hennessy, John L. "Computer Organization and Design." Morgan Kaufmann. 2020.
5. Stroustrup, Bjarne. "The C++ Programming Language." Addison-Wesley. 2013.