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.

Adding and Subtracting in Any Base (and Converting to a Common Base)

FORM 2 • TERM 1 • LESSON 07

In the last lesson you converted numbers from other bases into base 10. Now you will calculate in other bases. You will add and subtract in binary and other bases using the same column method you use in base 10, change base 10 numbers into other bases, and work with numbers that are written in different bases by putting them into one base first.

Learning outcomes

By the end of this lesson you should be able to:

  • 2.1.3.6 – Add and subtract numbers in any base, including binary.
  • 2.1.3.8 – Convert numbers to a single base so that they can be added or subtracted.

Changing a base 10 number into another base

To write a base 10 number in base b, divide by b again and again and write down each remainder. Stop when you reach 0, then read the remainders from the bottom up.

Divide by 2AnswerRemainder
45 ÷ 2221
22 ÷ 2110
11 ÷ 251
5 ÷ 221
2 ÷ 210
1 ÷ 201

Reading the remainders upwards gives 45 = 1011012. Check: 32 + 8 + 4 + 1 = 45. ✓

Adding in any base

Line up the digits in columns and add from the right, just as in base 10. The only change is when you carry: in base 10 you carry when a column reaches 10; in base b you carry when a column reaches b.

  • In binary: 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 102 (write 0, carry 1), and 1 + 1 + 1 = 112 (write 1, carry 1).
  • In base 5: if a column adds to 7, that is one 5 and 2 left over, so write 2 and carry 1.

For example, 2435 + 1345:

  1. Units: 3 + 4 = 7 = 1 × 5 + 2. Write 2, carry 1.
  2. Fives: 4 + 3 + 1 = 8 = 1 × 5 + 3. Write 3, carry 1.
  3. Twenty-fives: 2 + 1 + 1 = 4. Write 4.
  4. Answer: 4325.

Subtracting in any base

Subtract column by column from the right. When the top digit is too small, borrow 1 from the next column. In base 10 the borrowed 1 is worth 10; in base b it is worth b. In binary a borrowed 1 is worth 2.

For example, 3528 − 1678:

  1. Units: 2 − 7 cannot be done. Borrow 1 eight from the next column: 2 + 8 = 10, and 10 − 7 = 3.
  2. Eights: 5 became 4. 4 − 6 cannot be done. Borrow: 4 + 8 = 12, and 12 − 6 = 6.
  3. Sixty-fours: 3 became 2. 2 − 1 = 1.
  4. Answer: 1638.

Check by converting. 3528 = 234 and 1678 = 119. 234 − 119 = 115, and 1638 = 64 + 48 + 3 = 115. ✓

Numbers in different bases

You cannot add 11012 and 235 column by column, because their columns have different place values. First convert them to the same base – base 10 is usually easiest – then calculate. If the question asks for the answer in a particular base, convert the answer at the end.

Worked examples

Example 1: Base 10 to base 5

Question: Write 87 in base 5.

  1. 87 ÷ 5 = 17 remainder 2.
  2. 17 ÷ 5 = 3 remainder 2.
  3. 3 ÷ 5 = 0 remainder 3.
  4. Read the remainders upwards: 322.
  5. Check: 3 × 25 + 2 × 5 + 2 = 87. ✓

Answer: 3225.

Example 2: Binary addition

Question: Work out 10112 + 1102.

  1. Units: 1 + 0 = 1.
  2. Twos: 1 + 1 = 102. Write 0, carry 1.
  3. Fours: 0 + 1 + 1 (carried) = 102. Write 0, carry 1.
  4. Eights: 1 + 1 (carried) = 102. Write 0, carry 1 into a new column.
  5. Check: 11 + 6 = 17, and 100012 = 16 + 1 = 17. ✓

Answer: 100012.

Example 3: Binary subtraction

Question: Work out 11012 − 1102.

  1. Units: 1 − 0 = 1.
  2. Twos: 0 − 1 cannot be done. Borrow from the fours: 0 + 2 = 2, and 2 − 1 = 1.
  3. Fours: 1 became 0. 0 − 1 cannot be done. Borrow from the eights: 0 + 2 = 2, and 2 − 1 = 1.
  4. Eights: 1 became 0. Nothing is left.
  5. Check: 13 − 6 = 7 = 1112. ✓

Answer: 1112.

Example 4: Adding in base 3

Question: Work out 2123 + 1213.

  1. Units: 2 + 1 = 3 = 1 × 3 + 0. Write 0, carry 1.
  2. Threes: 1 + 2 + 1 = 4 = 1 × 3 + 1. Write 1, carry 1.
  3. Nines: 2 + 1 + 1 = 4 = 1 × 3 + 1. Write 1, carry 1 into a new column.
  4. Check: 23 + 16 = 39, and 11103 = 27 + 9 + 3 = 39. ✓

Answer: 11103.

Example 5: Mixed bases

Question: Work out 11012 + 235. Give your answer in base 10 and in base 2.

  1. Convert both to base 10: 11012 = 8 + 4 + 1 = 13, and 235 = 2 × 5 + 3 = 13.
  2. Add: 13 + 13 = 26.
  3. Change 26 to base 2: 26 = 16 + 8 + 2, so 26 = 110102.

Answer: 26, or 110102.

Example 6: Mixed-base subtraction

Question: Work out 2046 − 11112 and give the answer in base 10.

  1. 2046 = 2 × 36 + 0 × 6 + 4 = 76.
  2. 11112 = 8 + 4 + 2 + 1 = 15.
  3. 76 − 15 = 61.

Answer: 61.

Common mistakes

  • Carrying at 10 in every base. In base 5 you carry when a column reaches 5, and in binary when it reaches 2.
  • Borrowing 10 in every base. A borrowed 1 is worth the base: 8 in base 8, 2 in binary.
  • Writing a digit that does not exist. A digit 2 or more in a binary answer, or a 5 in a base 5 answer, means you forgot to carry.
  • Reading remainders top-down. When converting from base 10, read the remainders from the bottom up.
  • Adding numbers in different bases column by column. Convert them to one base first.

Practice questions

Try these yourself first, then open each answer to check your working.

1. Change to binary:
(a) 13
(b) 30
(c) 100.

Show answer

(a) 11012
(b) 111102
(c) 11001002.

2. Change to the base shown:
(a) 50 to base 5
(b) 100 to base 8
(c) 40 to base 3.

Show answer

(a) 2005
(b) 1448
(c) 11113.

3. Work out in binary:
(a) 1012 + 112
(b) 11102 + 10112
(c) 1112 + 1112.

Show answer

(a) 10002
(b) 110012
(c) 11102.

4. Work out in binary:
(a) 11002 − 1012
(b) 100002 − 12
(c) 110112 − 11102.

Show answer

(a) 1112
(b) 11112
(c) 11012.

5. Work out in the base shown:
(a) 345 + 235
(b) 2657 + 1547
(c) 578 + 368.

Show answer

(a) 1125
(b) 4527
(c) 1158.

6. Work out in the base shown:
(a) 425 − 135
(b) 2103 − 1023
(c) 4008 − 1258.

Show answer

(a) 245
(b) 1013
(c) 2538.

7. Work out 1012 + 123 + 214. Give the answer in base 10.

Show answer

5 + 5 + 9 = 19.

8. Work out 1005 − 10102. Give the answer in base 10 and in base 2.

Show answer

25 − 10 = 15 = 11112.

Quick check

1. What is 12 + 12?

Show answer

102.

2. In base 7, when do you carry?

Show answer

When a column reaches 7.

3. What should you do before adding 123 and 124?

Show answer

Convert them to the same base (for example base 10).

Previous: Number Bases: Place Value, Expanded Form, Binary and Converting to Base 10

Next: Algebra Review: Variables, Word Statements and Substituting Integers

Curriculum link: This post is relevant to the Trinidad and Tobago National Lower Secondary (NCSE) Mathematics Curriculum – Form 2, Term 1, Strand 2.1 Number Operations and Number Theory, Topic 2.1.3 Number Bases – Learning Outcomes 2.1.3.6 (adding and subtracting in any base, including binary) and 2.1.3.8 (converting numbers to a single base to calculate).

Updates

2026/10/23

– First version of this lesson.

2026/10/25

– Put each lettered part of the questions and answers on its own line.

© 2026 Vedesh Kungebeharry. All rights reserved.

Number Bases: Place Value, Expanded Form, Binary and Converting to Base 10

FORM 2 • TERM 1 • LESSON 06

We write numbers using ten digits, 0 to 9, and each place is worth ten times the place to its right. That is called base 10 (or the denary system). It is not the only way to write numbers. In this lesson you will meet other number bases, find the place value of digits in them, write numbers in expanded form, learn why computers use binary (base 2), and convert numbers into base 10.

Learning outcomes

By the end of this lesson you should be able to:

  • 2.1.3.1 – Explain what a number base is and recognise numbers written in different bases.
  • 2.1.3.2 – Find the place value of a digit in a number written in any base.
  • 2.1.3.3 – Write numbers in other bases in expanded form.
  • 2.1.3.4 – Explain why binary (base 2) is used in computers and other digital devices.
  • 2.1.3.5 – Convert numbers written in other bases to base 10.

What is a number base?

The base of a number system is how many digits it uses, and also the number you multiply by to move one place to the left.

  • Base 10 uses the digits 0–9. Place values: 1, 10, 100, 1,000, …
  • Base 5 uses the digits 0–4. Place values: 1, 5, 25, 125, …
  • Base 2 (binary) uses only 0 and 1. Place values: 1, 2, 4, 8, 16, …

In base b you can only use the digits 0 up to b − 1. So 2431 could be a base 5 number, but 2451 could not, because base 5 has no digit 5. We show the base with a small number written below and to the right, called a subscript: 10112 is “one zero one one, base two”. A number with no subscript is in base 10.

Place value in other bases

Each place is worth a power of the base. The place on the far right is always worth 1, because any base to the power 0 is 1.

Base5th place4th place3rd place2nd place1st place
10104 = 10,000103 = 1,000102 = 100101 = 10100 = 1
554 = 62553 = 12552 = 2551 = 550 = 1
884 = 4,09683 = 51282 = 6481 = 880 = 1
224 = 1623 = 822 = 421 = 220 = 1

The place value of a digit is the digit times the value of its place. In 24315, the 3 is in the 51 place, so it is worth 3 × 5 = 15.

Expanded form

Writing every digit times its place value, added together, is called expanded form. Adding up the parts gives the number in base 10:

24315 = 2 × 53 + 4 × 52 + 3 × 51 + 1 × 50 = 250 + 100 + 15 + 1 = 366.

This is also exactly how you convert to base 10. You met expanded form for base 10 in Form 1 in place value and number names; it works the same way in every base.

TRY ITConvert to base 10

Type a number written in a base from 2 to 9 and choose its base. The table shows the place value of every digit, and the expanded form adds them up to give the number in base 10.

Binary and computers

A computer is built from millions of tiny electronic switches. Each switch has only two states: off or on. That fits base 2 perfectly, because binary has only two digits: 0 for off and 1 for on. A single binary digit is called a bit, and 8 bits make a byte.

  • With 8 bits you can write every number from 0 to 111111112 = 255, which is 256 different values.
  • Letters are stored as numbers. In the common ASCII code, capital A is 65, stored as 10000012.
  • Pictures are grids of tiny dots (pixels), and the colour of each pixel is stored as binary numbers. Music, video and text messages are all stored the same way.
  • Two states are reliable: it is easy for a circuit to tell “on” from “off”, even when the signal is weak.
A large binary clock on the glass front of a Swiss railway station, with rows of lit and unlit symbols
Figure 1 – A binary clock at St. Gallen railway station, Switzerland. Each row of symbols shows part of the time in binary: a lit symbol stands for 1 and an unlit one for 0. Image: BBCLCD, CC BY-SA 4.0, via Wikimedia Commons.

Worked examples

Example 1: Which bases are possible?

Question: Which of these numbers could be written in base 4:
(a) 3021
(b) 1402
(c) 333?

  1. Base 4 uses only the digits 0, 1, 2 and 3.
  2. (a) 3021 uses 3, 0, 2, 1 – allowed. (b) 1402 has a 4 – not allowed. (c) 333 – allowed.

Answer: (a) and (c).

Example 2: Place value of a digit

Question: What is the value of the digit 6 in 36058? Give your answer in base 10.

  1. Places from the right: 80 = 1, 81 = 8, 82 = 64, 83 = 512.
  2. The 6 is in the 82 place.
  3. 6 × 64 = 384.

Answer: 384.

Example 3: Binary to base 10

Question: Convert 10112 to base 10.

  1. Expanded form: 1 × 23 + 0 × 22 + 1 × 21 + 1 × 20.
  2. = 8 + 0 + 2 + 1.

Answer: 11.

Example 4: A longer binary number

Question: Convert 1101012 to base 10.

  1. Place values from the left: 32, 16, 8, 4, 2, 1.
  2. Add the places with a 1: 32 + 16 + 4 + 1.

Answer: 53.

Example 5: Base 3 to base 10

Question: Write 21023 in expanded form and convert it to base 10.

  1. 2 × 33 + 1 × 32 + 0 × 31 + 2 × 30.
  2. = 54 + 9 + 0 + 2.

Answer: 65.

Example 6: Base 8 to base 10

Question: Convert 2478 to base 10.

  1. 2 × 82 + 4 × 81 + 7 × 80.
  2. = 128 + 32 + 7.

Answer: 167.

Common mistakes

  • Using a digit that is too big. Base 6 uses only 0 to 5, so “3626” is fine but “3726” is not a real number.
  • Starting the place values at the wrong end. The place on the right is always worth 1.
  • Thinking b0 is 0. Any base to the power 0 is 1, so the last digit is just itself.
  • Reading 1012 as “one hundred and one”. Say the digits: “one zero one, base two”. Its value is 5.
  • Forgetting the subscript. Without it, everyone will read the number as base 10.

Practice questions

Try these yourself first, then open each answer to check your working.

1. Which of these are not possible numbers in base 3? 1201, 2130, 22, 1003.

Show answer

2130 and 1003 (they use the digit 3, but base 3 only uses 0, 1 and 2).

2. Write down the place values of the first four places (from the right) in
(a) base 4
(b) base 7.

Show answer

(a) 1, 4, 16, 64
(b) 1, 7, 49, 343.

3. In base 10, what is the value of
(a) the digit 4 in 24135
(b) the 1 on the far left of 101102?

Show answer

(a) 4 × 25 = 100
(b) 1 × 16 = 16.

4. Write in expanded form:
(a) 30214
(b) 110012.

Show answer

(a) 3 × 43 + 0 × 42 + 2 × 41 + 1 × 40
(b) 1 × 24 + 1 × 23 + 0 × 22 + 0 × 21 + 1 × 20.

5. Convert to base 10:
(a) 1112
(b) 100102
(c) 111111112.

Show answer

(a) 7
(b) 18
(c) 255.

6. Convert to base 10:
(a) 435
(b) 12345
(c) 3056.

Show answer

(a) 20 + 3 = 23
(b) 125 + 50 + 15 + 4 = 194
(c) 108 + 0 + 5 = 113.

7. Convert to base 10:
(a) 648
(b) 20203
(c) 8769.

Show answer

(a) 48 + 4 = 52
(b) 54 + 0 + 6 + 0 = 60
(c) 648 + 63 + 6 = 717.

8. Give two reasons why computers store information in binary.

Show answer

Any two of: the electronic switches inside have only two states (off and on), which match the digits 0 and 1; two states are easy to tell apart reliably; every kind of data (numbers, letters, pictures, sound) can be coded as 0s and 1s.

Quick check

1. Which digits are used in base 2?

Show answer

0 and 1.

2. What is 1002 in base 10?

Show answer

4.

3. What is the value of the right-hand place in any base?

Show answer

1.

Previous: Index Form, Standard Form and Scientific Notation (Positive Powers)

Next: Adding and Subtracting in Any Base (and Converting to a Common Base)

Curriculum link: This post is relevant to the Trinidad and Tobago National Lower Secondary (NCSE) Mathematics Curriculum – Form 2, Term 1, Strand 2.1 Number Operations and Number Theory, Topic 2.1.3 Number Bases – Learning Outcomes 2.1.3.1 (the concept of number bases), 2.1.3.2 (place value in other bases), 2.1.3.3 (expanded form), 2.1.3.4 (why binary is used in computers) and 2.1.3.5 (converting to base 10).

Attributions to media used in this post:

Binary clock Swiss railway station.jpg – BBCLCD – CC BY-SA 4.0 (via Wikimedia Commons)

Updates

2026/10/23

– First version of this lesson.

2026/10/25

– Put each lettered part of the questions and answers on its own line.

© 2026 Vedesh Kungebeharry. All rights reserved.

Binary Manipulation

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.

Updates to this post

2026/10/15 – Substantially revised and expanded this lesson.

  • Reorganised the material into a step-by-step guide covering binary conversion, addition, subtraction, signed magnitude and two’s complement.
  • Added worked examples, comparison tables, practice exercises and answers.
  • Added optional concept explanations showing why the most significant bit has a negative weight in two’s complement, why we add 1, and how this makes binary arithmetic work.
  • Clarified signed integer ranges, negative zero and arithmetic overflow.

© 2026 Vedesh Kungebeharry. All rights reserved.

Decimal to binary

Task: Create an algorithm which accepts a decimal integer and outputs it’s binary equivalent.

This algorithm was designed and implemented in Flowgorithm:

See the video below for an explanation of how the algorithm works:

Decimal to binary algorithm explained

The code in C is shown below:



Copy and paste from here:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>//library needed for string operations

int main()
{
    //declare and identify integers
    int number, remainder;

    //declare, identify and initialize all strings
    char  result[20]="";
    char  remainderString[20]="";


    //initialize all other variables
    number=-1;
    remainder=-1;

    //get input
    printf("Enter a number in decimal\n");
    scanf("%d", &number);
    printf("\n");

    while (number!=0)
    {
        remainder=number%2;

            /* #Implementation_Result

                Here we implement the following:

                    result=remainder + result
            */

            //first convert the remainder to a string,
            //and store the converted data in "remainderString"
            itoa(remainder,remainderString,10);

            //add "remainderString" to "result" in that order.
            //the result of the concatenation is stored in "remainderString"
            strcat(remainderString,result);

            //now copy our data so far back to "result"
            strcpy(result,remainderString);
            /*End #Implementation_Result*/


        number=number/2;

    }

    printf("The binary Result is %s \n",result);
    return 0;
}

© 2019  Vedesh Kungebeharry. All rights reserved.