Return to Home Page       Return to Instructional Calendar

Computer Math How-To

Adding & Subtracting in Decimal, Binary, Octal, and Hexadecimal

All bases use the same column method (right → left). For addition, carry when a column reaches the base. For subtraction, borrow the base from the next column when needed. The only change is the base and the valid digits.

Universal Column Rules (Base b)

Addition

  1. Start at the least significant column (rightmost).
  2. Compute s = top + bottom + carry.
  3. Write s mod b in the column.
  4. Set carry = ⌊s / b⌋ and move left.
  5. After the leftmost column, write any nonzero carry in front.

Subtraction

  1. Start at the rightmost column.
  2. If top < bottom, borrow 1 from the next column to the left.
  3. Borrowing adds b to the current top digit; decrement the next column by 1.
  4. Compute top − bottom and move left.

Borrow adds: Binary +2, Octal +8, Hex +16.

Decimal (Base 10)

Addition Example

   carry:      1  1  1
        3  9  8  7
      + 2  5  6  8
      ----------------
        6  5  5  5   = 6,555₁₀
        

7+8=15 → write 5 carry 1; 8+6+1=15; 9+5+1=15; 3+2+1=6.

Subtraction Example

        4  0  0  3
      − 2  7  8  9
      ----------------
        1  2  1  4   = 1,214₁₀
        

Borrow chains through zeros: thousands becomes 3, hundreds 9, tens 9, ones 13.

Binary (Base 2)

Rules

  • Digits: 0 or 1 only.
  • Carry when a column ≥ 2; write sum mod 2, carry ⌊sum/2⌋.
  • Borrow adds 2 to the current bit.
a b carry-in digit carry-out
0 0 0 0 0
0 1 0 1 0
1 1 0 0 1
1 1 1 1 1

Examples

Add: 101101₂ + 011011₂

      101101
    + 011011
    --------
     1001000  = 72₁₀
          

Subtract: 101101₂ − 011011₂

      101101
    − 011011
    --------
      010010  = 18₁₀
          

Alternative: two’s complement of 011011₂ is 100101₂; add then drop overflow.

Octal (Base 8)

Rules

  • Digits: 0–7 only.
  • Carry when a column ≥ 8; write sum mod 8, carry ⌊sum/8⌋.
  • Borrow adds 8 to the current column.

Examples

Add: 753₈ + 246₈

        7 5 3
      + 2 4 6
      --------
        1 2 2 1  = 1221₈
          

3+6=9→write1 carry1; 5+4+1=10→write2 carry1; 7+2+1=10→write2 carry1→leading 1.

Subtract: 1203₈ − 746₈

        1 2 0 3
      −   7 4 6
      --------------
            2 3 5  = 235₈
          

Borrow through the zero: ones 3<6→borrow→(11₈−6)=3; tens 7−4=3; hundreds 1<7→borrow from thousands.

Hexadecimal (Base 16)

Rules

  • Digits: 0–9 and A–F (A=10, …, F=15).
  • Carry when a column ≥ 16; write sum mod 16, carry ⌊sum/16⌋.
  • Borrow adds 16 to the current column.
Dec Hex Dec Hex Dec Hex Dec Hex
10 A 11 B 12 C 13 D
14 E 15 F 16 10 17 11

Examples

Add: 3A7₁₆ + C9D₁₆

        3  A  7
      +  C  9  D
      -----------
        1  0  4  4   = 1044₁₆
          

7+D=20→write 4 carry1; A+9+1=20→write 4 carry1; 3+C+1=16→write 0 carry1→leading 1.

Subtract: F2B₁₆ − 8DE₁₆

        F  2  B
      − 8  D  E
      -----------
        6  4  D   = 64D₁₆
          

B(11)<E(14) → borrow: (11+16)−14=D; middle 1<D → borrow from F: (1+16)−13=4; top E−8=6.

Quick Checks & Tips

```