Binary Representation and Manipulation: A Step-by-Step Guide

Computer Science – Number Systems and Data Representation

Computers store integers as patterns of bits. This tutorial explains how binary works, how to perform arithmetic, and how signed magnitude and two’s complement represent negative values.

Learning objectives

  • Convert positive decimal integers to binary and back.
  • Add and subtract binary integers.
  • Explain signed magnitude and two’s complement.
  • Represent signed integers using a specified number of bits.
  • Determine the range of integers supported by two’s complement.

1. Understanding binary numbers

A bit is a binary digit: 0 or 1. Decimal (base 10) uses powers of 10; binary (base 2) uses powers of 2. The place values, from right to left, are 1, 2, 4, 8, 16, 32 and so on.

Binary place value8421
Binary 01100110

Convert binary to decimal

Multiply each binary digit by its place value and add the results.

110₂ = (1 × 4) + (1 × 2) + (0 × 1) = 6₁₀. Similarly, 11₂ = (1 × 2) + (1 × 1) = 3₁₀.

The subscript ₂ means binary and ₁₀ means decimal.

2. Converting decimal to binary

Repeatedly divide the positive decimal number by 2, recording the quotient and remainder. Stop when the quotient becomes 0. Read the remainders from bottom to top.

Worked example: Convert 13₁₀ to binary

DivisionQuotientRemainder
13 ÷ 261
6 ÷ 230
3 ÷ 211
1 ÷ 201

Reading the remainders upwards gives 13₁₀ = 1101₂. Check: 8 + 4 + 0 + 1 = 13.

Try it: Convert 6, 9 and 18 to binary before reading the answers below.

3. Binary addition

OperationResult
0 + 00
0 + 11
1 + 01
1 + 110 (write 0, carry 1)

Worked example: Add 6 and 3

6₁₀ = 0110₂ and 3₁₀ = 0011₂.

    0110
  + 0011
  ------
    1001

Therefore, 0110₂ + 0011₂ = 1001₂. Check: 6 + 3 = 9, and 1001₂ = 8 + 1 = 9. Add from the right, carrying when a column totals 2 or 3.

4. Binary subtraction

Subtract from right to left. When you encounter 0 − 1, borrow from the next available 1 to the left. A borrowed 1 represents binary 10 (decimal 2) in the current column.

Worked example: Subtract 3 from 6

    0110
  - 0011
  ------
    0011

In the rightmost column, 0 − 1 requires borrowing. The next column then also requires borrowing from the column to its left. The answer is 0011₂ = 3₁₀, as expected.

5. Signed magnitude representation

For signed magnitude, the most significant bit (MSB) is the sign: 0 for positive, 1 for negative. The remaining bits give the magnitude (absolute value). The number of bits must be specified.

Decimal8-bit signed magnitude
+600000110
−610000110
+300000011
−310000011

An 8-bit signed-magnitude system represents values from −127 to +127. It has two encodings for zero: positive zero (00000000) and negative zero (10000000).

6. Two’s complement representation

Two’s complement is widely used for signed integers. To represent a negative number with a fixed number of bits:

  1. Write the positive integer in binary using the required bit width.
  2. Invert every bit (0 becomes 1; 1 becomes 0).
  3. Add 1.

Worked example: Represent −6 using 8 bits

Step 1: +6 = 00000110

Step 2: Invert all bits → 11111001

Step 3: Add 1.

  11111001
+        1
----------
  11111010

Therefore, −6 = 11111010 in 8-bit two’s complement.

Shortcut: Copy and invert

Starting at the right, copy digits up to and including the first 1; then invert every digit further left. Applied to 00000110, this produces 11111010.

Comparing signed magnitude and two’s complement

DecimalSigned magnitude (8 bits)Two’s complement (8 bits)
+60000011000000110
−61000011011111010
+30000001100000011
−31000001111111101

Important: The same bit pattern can mean different values depending on which representation is used. The MSB of a two’s complement number has a negative place value, unlike the separate sign bit in signed magnitude.

Optional concept explanations: The next two notes go beyond the basic conversion and arithmetic procedures. They are provided for students who want to understand why two’s complement works. You may skip them on a first reading and return to them after practising the examples.

Concept note: Why the leftmost bit is negative in two’s complement

Reconciliation note: In a fixed-width two’s complement number, the most significant bit (MSB) carries a negative place value. It is not a separate sign bit as it is in signed magnitude. For three bits, the weights from left to right are −4, +2 and +1, instead of +4, +2 and +1.

There are 2³ = 8 different three-bit patterns. Using two’s complement, these represent all integers from −4 through +3:

Decimal value3-bit two’s complementUsing weights −4, +2, +1
00000
+10011
+20102
+30112 + 1
−1111−4 + 2 + 1
−2110−4 + 2
−3101−4 + 1
−4100−4

Check the negatives: 111 = −4 + 2 + 1 = −1; 110 = −4 + 2 = −2; 101 = −4 + 1 = −3; and 100 = −4.

Why this makes sense: A three-bit system has eight patterns but cannot represent every integer. By giving the MSB a weight of −4, two’s complement uses those patterns to represent four non-negative values (0 to +3) and four negative values (−1 to −4), with only one representation of zero. This is a mathematical interpretation of the two’s complement system, not a historical claim about its invention.

One subtlety: In binary pattern order, 011 is followed by 100. As signed three-bit values, those mean +3 and −4. Adding 1 to +3 therefore overflows the signed range; it does not mean +3 + 1 equals −4 in ordinary mathematics.

Concept note: Why do we add 1 in two’s complement?

First, an important distinction: It is one’s complement (and signed magnitude), not two’s complement, that has both positive zero and negative zero. In one’s complement, changing a positive value to its negative requires only flipping every bit. For example, in 3 bits, 000 is +0 and 111 is −0.

Two’s complement uses invert the bits, then add 1. That extra 1 changes the negative-number patterns so 111 becomes −1 instead of −0, while 000 is the only zero. The freed-up bit pattern 100 represents −4, giving the 3-bit two’s complement range −4 to +3.

Compare every possible 3-bit pattern:

3-bit patternOne’s complement valueTwo’s complement value
000+00
001+1+1
010+2+2
011+3+3
100−3−4
101−2−3
110−1−2
111−0−1

Worked example: Find −2 using 3-bit two’s complement. Start with +2 = 010. Flip its bits to obtain 101 (this is −2 in one’s complement). Add 1: 101 + 001 = 110. In two’s complement, 110 is −2 because (1 × −4) + (1 × 2) + (0 × 1) = −2.

What happens to negative zero? Invert 000 to get 111, then add 1: 111 + 001 = 1000. With only 3 bits, discard the carry beyond the third bit, leaving 000. So negative zero becomes the same bit pattern as zero: no separate −0.

Why the arithmetic works: step by step (optional)

Step 1 — There are eight patterns. With 3 bits, there are 2³ = 8 possible patterns, from 000 to 111. The largest unsigned 3-bit value is 7 (111).

Step 2 — Flipping bits gives the complement to 7, not to 8. Let us start with +2, written as 010. When we flip every bit, we obtain 101, which is 5 if read as an unsigned number. Notice that 2 + 5 = 7 (binary 111), not 8. This is why simply inverting the bits gives one’s complement.

Step 3 — Adding 1 completes the full eight. Add 1 to 101 to get 110 (6 as an unsigned value). Now 2 + 6 = 8, which is 1000 in binary. In a fixed-width 3-bit operation, the leftmost carry is discarded, leaving 000. Thus 110 acts as −2 when added to +2 using 3-bit arithmetic.

  010   (+2)
+ 110   (−2 in 3-bit two’s complement)
-----
 1000   (discard the carry beyond 3 bits)
  000   (zero)

Step 4 — That lets subtraction use addition. To calculate 3 − 2, write +3 as 011 and −2 as 110. Add them as ordinary binary numbers: 011 + 110 = 1001. Keep the lowest 3 bits, 001, which equals +1. Therefore, 3 + (−2) = 1.

General rule: With n bits, flipping the bits of a number x produces (2n − 1) − x. Adding 1 produces 2n − x. Consequently, x + (2n − x) = 2n, whose lowest n bits are all zero. This is the mathematical reason for the “+1”. It gives an additive inverse using fixed-width binary arithmetic and also eliminates the separate negative-zero representation found in one’s complement.

Important limitation: This works for results representable within the chosen signed bit width. A calculation outside the range (−4 to +3 for three bits) causes signed overflow, so discarding a carry must not be mistaken for a valid result in every case.

7. Subtraction using two’s complement

Subtraction can be rewritten as addition: 6 − 3 = 6 + (−3).

Represent +6 as 00000110 and −3 as 11111101 in 8-bit two’s complement.

    00000110  (+6)
  + 11111101  (−3)
  ----------
  1 00000011

Discard the carry beyond the eighth bit. The 8-bit result is 00000011 = +3. In signed arithmetic, also check whether the true result fits the selected bit width; discarding the carry alone does not guarantee that overflow has not occurred.

8. Finding the largest and smallest two’s complement integers

For an n-bit two’s complement system, the largest integer is 2n−1 − 1 and the smallest is −2n−1.

Worked example: A 4-bit system

Largest: 2³ − 1 = +7. Smallest: −2³ = −8.

4-bit two’s complementDecimal
0111+7
00000
1111−1
1000−8

The 4-bit two’s complement range is −8 to +7, whereas 4-bit signed magnitude represents −7 to +7.

9. Common mistakes to avoid

MistakeCorrect approach
Reading division remainders from the topRead them from the bottom to the top.
Forgetting to carry in binary additionCarry 1 when a column totals binary 10 or 11.
Changing only the sign bit for two’s complementInvert all bits and add 1.
Using an inconsistent number of bitsKeep a fixed, stated bit width for signed calculations.
Assuming every discarded carry means a valid signed resultCheck for signed overflow as well.
Assuming the greatest 4-bit signed integer is 15It is +7 in 4-bit two’s complement.

10. Practice exercises

  1. Convert 19₁₀ to binary.
  2. Convert 101101₂ to decimal.
  3. Add 1011₂ and 0110₂.
  4. Subtract 0101₂ from 1100₂ using ordinary binary subtraction.
  5. Represent −9 in 8-bit two’s complement.
  6. Calculate 7 − 6 using 8-bit two’s complement addition.
  7. State the lowest and highest integers that 6-bit two’s complement can represent.

Answers

QuestionAnswer
110011₂
245₁₀
310001₂ (17₁₀)
40111₂ (7₁₀)
511110111
600000001 (+1)
7−32 to +31

11. Related lessons and further practice

Final takeaway

Binary representation is more than memorising strings of zeros and ones. Understanding place values, carrying, borrowing, signed magnitude and two’s complement helps explain how computers store and manipulate integer data. Verify answers by converting back to decimal whenever possible.

© 2026 Vedesh Kungebeharry. All rights reserved.

Spreadsheet Formulas and Functions – Practice Exercise (Form 2 ICT)

Form 2 ICT | Chapter 33: Spreadsheets – Formulas | Specific Objective 3.11

Practise writing Excel formulas using cell references, arithmetic operators and the SUM, AVERAGE, MAX and MIN functions. This is a written exercise: you do not need to open Excel.

The spreadsheet

The spreadsheet below shows the marks obtained by five students in three assessments. The cells for calculated results are blank.

 ABCDEFG
1StudentEnglishMathematicsScienceTotalAverageDifference
2Amir786582   
3Bianca859088   
4Carlos607268   
5Diana929590   
6Ethan706875   
7Total      
8Average      
9Highest      
10Lowest      

Your task (8 marks)

Using the cell references shown in the spreadsheet, write the Excel formula or function required for each task. Begin each formula with an equals sign (=).

  1. Calculate Amir’s total marks in cell E2 using the addition operator (+). (1 mark)
  2. Calculate Bianca’s average mark in cell F3 using arithmetic operators, without using the AVERAGE function. (1 mark)
  3. Calculate Carlos’s total marks in cell E4 using the SUM function. (1 mark)
  4. Calculate the total English marks in cell B7 using the SUM function. (1 mark)
  5. Calculate the average Mathematics mark in cell C8 using the AVERAGE function. (1 mark)
  6. Calculate the highest Science mark in cell D9 using the MAX function. (1 mark)
  7. Calculate the lowest English mark in cell B10 using the MIN function. (1 mark)
  8. Calculate the difference between Diana’s Mathematics mark and her English mark in cell G5 using the subtraction operator (−). (1 mark)

Total: 8 marks.

Note: Use the operator or function named in each part. A formula such as =B2+C2 uses cell references, while =SUM(B2:B6) uses a function.

Form 3 ICT – Spreadsheet Calculations and Formatting Tutorial (SO 3.11)

Purpose: Practise creating a worksheet, calculating totals and averages, copying formulas, using MIN and MAX, applying arithmetic operators and formatting numbers. This tutorial uses a new dataset.

1. Enter the practice data

Open Microsoft Excel. Click cell B3 and paste the following tab-separated table. Leave the Total Sales and Average Sales cells blank.

ProductWeek 1Week 2Week 3Week 4Total SalesAverage Sales
USB Drives12181520
Wireless Mouse20141719
Keyboards9121114
Webcams15101312
Headsets18222016
Laptop Stands711913
Maximum
Minimum

Next, click cell J3 and paste this second table:

Data TypeValue
Unit Price25.50
Discount Rate0.15
Sale Date8-Oct-2026
Stock Count350

2. Calculate totals with SUM

Click G4. Type the formula below and press Enter. SUM adds the values in cells C4 through F4.

=SUM(C4:F4)

Copy G4 and paste into G5. Notice that Excel adjusts the row references. Undo that paste. Return to G4 and drag the small square at the bottom-right corner of the cell (the Fill Handle) down to G9. Click G9 and check that its formula is:

=SUM(C9:F9)

3. Calculate averages

Click H4, enter the formula below, and press Enter. Drag the Fill Handle down to H9. Select H4:H9 and format the results to two decimal places.

=AVERAGE(C4:F4)

4. Find maximum and minimum values

Click G10 and enter the formula for the highest total. Then click G11 and enter the formula for the lowest total.

=MAX(G4:G9)
=MIN(G4:G9)

In two empty cells, find the lowest and highest Week 2 sales figures:

=MIN(D4:D9)
=MAX(D4:D9)

5. Practise arithmetic operators

Every Excel formula begins with =. Enter each of these formulas in a separate empty cell and observe the result:

Addition: The + sign adds values.

=C4+D4+E4+F4

Subtraction: The – sign subtracts values.

=D4-C4

Multiplication: The * sign multiplies Week 1 sales by the unit price.

=C4*K4

Division: The / sign divides the total by four.

=G4/4

6. Apply number formats

Use the second table beginning at J3. Select K4 and apply Currency format. Select K5 and apply Percentage format; 0.15 should display as 15%. Select K6 and apply Date format. Select K7 and apply Number format.

7. Troubleshooting and recap

If a cell displays #### instead of its value, the column is usually too narrow. Widen the column instead of re-entering the formula.

Remember: SUM adds, AVERAGE finds the mean, MAX finds the highest value, MIN finds the lowest value. Recognise +, -, * and /; use the Fill Handle to copy formulas; and distinguish Number, Currency, Percentage and Date formats.

Teacher check (answers)

USB Drives: Total Sales = 65; Average Sales = 16.25. Highest total = 76; lowest total = 40.