Number Base
arithmetic.
Add, subtract, multiply or divide in binary, hex or any base up to 36, with the steps.
- Decimal
- 286
- Digits
- 3
Each digit of B gives one row, and the rows are added in base 16. The answer has 3 digits in hexadecimal and is exact, however long the numbers get.
Written working
In base 161A × B worked in columns in base 16, one row for each of the 1 digits of the bottom number. The answer is 11E in base 16.
Working
- 1Multiply the top number by each digit of the bottom one, moving one place left for each digit1A × B = 11E₁₆
- 2Check in decimal: do the same sum in base 10 and convert back26 × 11 = 286, and 286 = 11E₁₆
- 3Check: undo the operation and get the first number back11E ÷ B = 1A₁₆ ✓
Facts in base 16
B plus and times each digit, base 16
| Digit | B + digit | B × digit |
|---|---|---|
| 0 | B | 0 |
| 1 | C | B |
| 2 | D | 16 |
| 3 | E | 21 |
| 4 | F | 2C |
| 5 | 10 | 37 |
| 6 | 11 | 42 |
| 7 | 12 | 4D |
Check a list
Answers
| Problem | Answer | Decimal |
|---|---|---|
| 1A × B | 11EDecimal 286 | 286 |
| FF × 2 | 1FEDecimal 510 | 510 |
| 7D × 3 | 177Decimal 375 | 375 |
| 100 × 10 | 1000Decimal 4,096 | 4,096 |
How it's worked out
In base , each digit is worth its own value times a power of , counted from 0 at the right. Digits above 9 are letters: A is 10, B is 11, and Z is 35.
The paper methods from school work in every base. Only the point where a column overflows changes. OpenStax puts it simply: set the sum up as in base 10 and use the addition table for the base. In hex, A9 + 94 adds 9 + 4 = 13, which is the digit D. Then A + 9 = 19, which is 16 + 3, so you write 3 and carry 1. The answer is 13D.
Subtraction borrows one of the base, not 10, from the next column. Multiplication writes one row per digit of the second number, each moved one place left, then adds the rows in the base. Long division brings down one digit at a time and asks how many times the divisor fits.
The tool reads both numbers as exact whole numbers of any length, does the sum, and writes the answer in the base you pick. It then checks the result in decimal and by undoing the operation.
Worked examples
Sam checks a hex product from a register map
Sam needs 1A × B in hex. B is one digit, so there is one row: 11E. In decimal that is 26 × 11 = 286, and 286 is 11E in hex.
The undo check divides 11E by B and gets 1A back. OpenStax works a two-row product the same way: 3A × 74 in base 12 is 2414.
Ana works a base 6 subtraction with a borrow
In the ones column 2 is less than 4, so Ana borrows one six from the 5. The ones digit becomes 2 + 6 = 8, and 8 − 4 = 4. The 5 is now 4, and 4 − 3 = 1.
So 52 − 34 = 14 in base 6. In decimal that is 32 − 22 = 10, which matches.
A base 5 long division with a remainder
23 in base 5 does not go into 4, so the first quotient digit is 0. It goes into 43 once, leaving 20. Carry on bringing down digits and the quotient is 140 with remainder 1.
Check in decimal: 586 ÷ 13 = 45 remainder 1, and 45 is 140 in base 5.
Reading your result
The answer is in the base you choose, with the decimal value beside it. Division gives a whole-number quotient and a remainder. Every result is exact, so FFFFFFFFFFFFFFFF + 1, one more than the largest 64-bit value, comes out as 18,446,744,073,709,551,616 in decimal with no rounding.
The facts table answers the lookup that slows people down. In base 5, 3 + 4 = 12 and 3 × 4 = 22. In octal, 7 × 7 = 61. A carry happens whenever a fact has two digits.
Negative numbers follow the usual sign rules. 5 + (−9) is worked as 9 − 5 and given a minus sign, so it is −4. Division rounds toward zero, so −7 ÷ 2 is −3 remainder −1.
Hex offsets are the everyday case for programmers. A buffer at address 7FF0 with an offset of 20 hex (32 bytes) ends at 8010. That one sum carried 2 times, which is the step people get wrong when they add hex in their head.
Binary follows the same rules. 1001011 ÷ 11 is 11001 with remainder 0, which is 75 ÷ 3 = 25 in decimal.
Common mistakes
- Carrying at 10. In octal, 7 + 1 fills the column, so 777 + 1 = 1000. If you carry only at 10, you write 778, and 8 is not even an octal digit.
- Borrowing 10. A borrow adds the base. In base 6 the borrowed column gets 6 more, not 10.
- Reading 10 as ten. In any base, 10 means one of the base and nothing more. It is 2 in base 2, 8 in base 8, 16 in base 16.
- A digit that does not exist. G is not a hex digit and 5 is not a base 5 digit. The boxes refuse them, but on paper they slip in when a fact is misremembered.
- Mixing bases. Both numbers must be in the same base. Convert one first if they start in different ones.