0% found this document useful (0 votes)
4 views22 pages

Programming Concept Chapter 2

The document provides an overview of programming concepts, including definitions of computer programs, programming languages, and the roles of programmers. It categorizes programming languages into five generations and explains the characteristics of machine, assembly, high-level, fourth, and fifth generation languages. Additionally, it covers data types, operators, errors, and the problem-solving methodology in programming, including algorithms and flowcharts.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views22 pages

Programming Concept Chapter 2

The document provides an overview of programming concepts, including definitions of computer programs, programming languages, and the roles of programmers. It categorizes programming languages into five generations and explains the characteristics of machine, assembly, high-level, fourth, and fifth generation languages. Additionally, it covers data types, operators, errors, and the problem-solving methodology in programming, including algorithms and flowcharts.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ODISHA ADARSHA VIDYALAYA

CLASS-VIII PROGRAMMING CONCEPT NOTE


COMPUTER PROGRAM :
 A Computer Program is a sequence of instructions to process certain input and produces desired
output.
WHAT IS PROGRAMMING :
 The process of writing the sequence of logical steps using a computer language is called
programming.
SYNTAX :
It refers to the rules and regulations for writing any statement in a programming language.
PROGRAMMERS :
The persons who writes the codes to design any programming language are called as Programmers.

GENERATIONS OF COMPUTER LANGUAGE :

Computer Programs are written in various languages which are also called programming
languages which are classified into five categories :
a) Machine Language
b) Assembly Language
c) High Level Language
d) 4th Generation Language
e) 5th Generation Language

MACHINE LANGUAGE :
 A Machine language is a computer language which consists of only 0’s and 1’s.
 The Machine Language is written in binary form which is only understood by the computers.
 Also called as the language of the CPU.

ASSEMBLY LANGUAGE :
 It is a form of computer language where mnemonic codes are used for writing programs.
 An assembler is required to convert an assembly language program into machine language.
 Ex. MOV, ADD, MUL
 Because the computer only understands the machine language (0’s and 1’s), the assembly language
have to be converted into machine language .
 The translator program involved in the process of converting assembly language to machine language
is called assembler.
HIGH LEVEL LANGUAGE :
 A high level language is a English –level language used for writing computer programs.
 The high level languages are not in the machine readable form so it requires an
interpreter/compiler to translate the language into machine understandable form.
TYPES OF TRANSLATOR PROGRAMS USED IN HIGH LEVEL LANGUAGE :

Two types of translator programs used are :

Interpreter :- It is a translator program used to convert high level language into machine language line by
line.

Compiler:- It is a translator program used to convert the high level language into machine language. It
translates the whole program at once.

HOW DOES INTERPRETER CONVERTS A HIGH LEVEL LANGUAGE PROGRAM INTO A MACHINE READABLE
FORM :
1. Interpreter reads and translates the high level language program line by line into machine
readable form.
2. It converts one line into machine understandable form executes the instruction , repeats the
same procedure for remaining instructions .
3. Errors ,if any in each line are immediately identified and removed.

HOW DOES COMPILER CONVERTS A HIGH LEVEL LANGUAGE PROGRAM INTO A MACHINE READABLE FORM
[Link] reads the whole program and translates the entire program into machine understandable
form at once.
2. It generates the object code for the program.
3. If any error in the program , the error is displayed at once after the compilation.

DEFINE SOURCE CODE AND OBJECT CODE :


Source Code :- The programming code which is written in high level language(English specific language)
by the user / programmer is called as source code.
Object Code:- It is generated from source code after going through compiler/ interpreter.
Object Code contains a sequence of machine instructions to which CPU understands and
executes.

One word based points to remember :


BASIC :- Beginners All Purpose Symbolic Instruction Code.
COBOL :- Common Business Oriented Language.
FORTRAN :- Formula Translation.
LOGO :- Logic Oriented Graphic Oriented Programming Language.
OOP- Object Oriented Programming.
VB – It is a programming language in which a programmer uses GUI (Graphical User Interface).
PYTHON is created by :GUIDO VAN ROSSUM.
CLASSIFICATION OF LANGUAGES ACCORDING TO THEIR GENERATION :
 Machine Language - 1st Generation
 Assembly Language - 2nd Generation
 High Level Language - 3rd Generation

FEATURES OF VARIOUS LANGUAGES :

LANGUAGES FEATURES
Only Binary codes are used (0's & 1's)
MACHINE Machine dependent

This language is only understandable by Computer.


Machine dependent
ASSEMBLY Translators like "Assemblers" are used for converting assembly
language to machine language.

English words and Arithmetic operators are used.


Machine independent
HIGH LEVEL
Translators like "Interpreters" & "Compilers" are used to convert
into machine language

High user friendly


4th GENERATION
Very high speed execution
LANGUAGE
Reduced level of programming skills ex- SQL

Use of AI (Artificial Intelligence) to meet the goal.


5th GENERATION
LANGUAGE The AI technique supports human like self learning & problem
solving.

HOW IS 4TH GENERATION LANGUAGE DIFFERENT FROM OTHER GENERATIONS OF PROGRAMMING


LANGUAGES :

In 4GL type of languages , the user has to only specify the required output and the format of the output
without thinking about the steps required to obtain that.

One word based points to remember :

first computer language for writing AI : LISP


first lady computer programmer : LADY ADA LOVELACE
first computer language lisp was created by : JOHN Mc Carthy.
First interactive computer game : SPACE WAR
Software tem was first coined by :JOHN W TURKEY
CONSTANTS :
Constants are the quantities whose values don’t change during the execution of the program.

CHARACTER CONSTANTS :

 These are alpha numeric & special characters like ‘A’ to ‘Z’ , ‘a’ to ‘z’ , ‘0’ to ‘9’. & other special
characters.

NUMERICAL CONSTANTS :
Represented by numbers.
Ex. 534, 262, 15.72, -42.

STRING CONSTANTS :
 Sequence of alphabetic numeric characters enclosed in double quotation marks.
 Ex “Male”, “Female”, “India” .

VARIABLES :
 A variable is a user-defined name that holds a value in computer memory that can be changed
during the program execution.

 Ex- X= 10 Here X is a variable which holds value 10.


SchoolName= “OAV” SchoolName is a variable which holds value OAV .
Percentage =89.26 Percentage is a variable which holds value 89.26.

DATA TYPES :

A datatype specifies the type of value a variable can contain. The amount of memory a variable can
hold depends upon the data type by which it is declared.
Data types can be of three types –
Character type-
Allows variables to store character type data.
Ex. ‘b’, ‘D’, ‘&’ .
Occupies 1 bytes of memory.
Integer type –
Allows variables to hold integer / numeric type values .
Ex. -20, 0, 12 .
Occupies 2 bytes of memory.
Float type –
Allows variables to hold floating point/ decimal type values .
Ex : 2.0, 3.1415, -100.876
Occupies 4 bytes of memory
OPERATORS :
 Operators are the symbols that are used to perform some specific mathematical, relational or logical
operations on values and variables.
 The values and variables used with operators are called operands.

Arithmetic Operators :- Arithmetic operators are used to perform mathematical calculations like addition,
subtraction, multiplication, and exponentiation.
Result
Operator Operation Description Examples
Let A=12,B=2

+ Addition Gives the sum of values A+B 14

- Subtraction Gives the difference of values A-B 10

x Multiplication Gives the product ofvalues AXB 24

/ Division Gives the quotient A/B 6

^ Exponentiation Raise the value to thepower of an exponent A^ B 144

MOD (%) Modulus Gives the remainder after division A MOD B or A % B 0

Precedence of Arithmetic Operators:-


The precedence of the operator is the priority given to each operator in an expression. The precedence
decides the order in which the expression is evaluated.

Symbol Operator Priority Level


First priority. In an expression the
( ) Parenthesis operations within ( ) are to be
resolved first
^ Exponentiation Second Priority

* or / Multiplication or Division Third Priority

MODULUS(%) Modulo operator Fourth Priority

+ or - Addition or Subtraction Fifth Priority


When two operators of the same priority are found in the expression, precedence is given to the extreme
left operator and the evaluation of the expression is done from Left to Right .

Examples :
(i) X= 5 x 4 + 8 / 2
Step -1 : Though x and / have the same priorities. Therefore 5 x 4 is solved first, result obtained 20.
5 x 4 + 8/2
Step – 2 : In the above expression / have higher priority than + . Therefore 8 / 2 is solved, result obtained 4.
20 + 8/2
Step- 3: + is evaluated next. 20 + 4 ,
20 + 4
Finally the result obtained is 24 .

(ii) ( 8 / ( 2 x ( 2 x 2 ) ) )
Step – 1 : Parenthesis has the higher priority above all operator. Therefore Innermost bracket is
evaluated first. i.e 2 x 2 =4.
(8 / ( 2 x (2 x 2 ) ) )
Step – 2 : Second Inner most bracket is evaluated next. 2 is multiplied with the result of innermost
bracket . The result thus obtained from step 2 is 2 x 4 = 8.
(8 / ( 2 x 4 ) )
Step – 3 : The outermost is evaluated . 8 is divided by 8 and result thus obtained is 1.
(8/8)
Finally the result obtained is 1.

(iii) 10 + 20 x 30
Step -1 : x has higher priority than +, so the first evaluation will be –
10 + 20 x 30
Step -2 : + operator will be evaluated next
10 + 600
Finally the result obtained is 610 .

(iv) 100 / 5 % 2
Step -1 : Because both / (division) and % (Modulus) are of same priority, the order of evaluation will be
from left to right. 100 / 5 result thus obtained is 20.
100 / 5 % 2
Step -2 : % (modulus) will be evaluated next.
20 % 2
Finally the result obtained is 0 .

Practice Questions :
(i) 100 + 200 /10 -3 x 10
(ii) 3 x ( 4 + 2 ) x 6
(iii) a= 9, b= 12, c= 3 , find the value of x , y & z.
x= a-b / 3 + c x 2 – 1
y= a- b / ( 3 + c) x ( 2 -1 )
z= a- ( b/ ( 3 + c ) x 2 )-1

Relational Operators :- Relational operators are used to perform comparisons of the two operands. The
result of comparison may either return True ( 1 ) or False ( 0 )
Result
Operator Operation Description Examples
Let A=25,B=5
Returns true (1) if the left value is less than
< Less than A<B 0
right value else false (0)
Returns true (1) if the left value is greater
> Greater than A>B 1
than right value else false (0)
Less than or Returns true (1) if the left value is less than
<= A <= B 0
equals to or equals to the right value else false (0)
Greater than or Returns true (1) if the left value is greater
>= A >= B 1
equals to than or equals to the right value else false (0)
Returns true (1) if both the values are equal
== Equals to A == B 0
else false (0) if not equal .
Returns true (1) if both the values are not
!= Not equals to A != B 1
equals else false if both values are equal

Assignment Operators :- Assignment operators are used to assign value to a variable. The left side operand is
a variable and the right side operand is a value. The = (equals to ) operator assigns value on the right side to
the variable on the left.
Ex- A=25

Logical Operators : Logical operators perform logical operations on two or more conditions and returns either
True ( 1 ) or False ( 0 )
Example
Operator Description Result
Let A=5,B=3
Returns true (1) if both the operands are
AND ( &&) (A > 3) && (B < 5) 1 (True)
true (1) else false (0)
Returns true (1) if both the operands or any
OR ( II ) (A >3) II (B < 5) 1 (True)
one of the operand are true (1) else false (0)
NOT ( ! ) Returns true (1) if the operand is false(0) !( A > 3) 0 (False)

EXPRESSION :

 An expression consists of operands and operators, where operands are represented for values
and operators are symbols which represent particular actions.
 Expression which represents numeric values is called an Arithmetic Expression.
 Ex. X + 3 is an expression where X , 3 is an operand and + is an operator
ERRORS :

 Errors are the problems or the faults that occur in the program which makes the behavior of the
program abnormal and should be removed for the successful execution of the program.
 Programming errors are also known as faults or bugs and the process of removing these bugs
known as debugging.
 Errors are detected either during compilation or execution.

TYPES OF ERRORS :

 Compilation Errors- These are caught during compilation.


 Syntax Errors – These errors occur when code violates the rules of the programming language
such as missing semicolons, brackets or use of undeclared variable etc.
 Semantic Errors- Occurs because of meaningless statements.
 Type Error – Occurs when a value of one data type is assigned to variable of another datatype.
 Runtime Errors – These errors occur during runtime of the program.
 Logical Errors – These are the types of errors that occurs when incorrect logic is implemented in
the code that produces unexpected output.

PROBLEM SOLVING METHODOLOGY :

A Program development process is the step by step process in converting input to output.
Steps involved in a program development
 Analysis – This is the phase where all the requirements of the program like different inputs and
corresponding outputs are analyzed & gathered.
 Design- The step by step procedures of the program are represented either in the form of
algorithm / flow chart.
 Coding – The algorithm is translated to a source code using some programming language .
 Compile / Test the program – It translates the whole program at once into the object code for
execution .
 Execute the program – After compilation an error free program is put to run to produce the
desired output.

ALGORITHM & FLOWCHART :

An algorithm is a finite set of instructions, which is to be carried out in order to solve a particular
task.
Characteristics of an algorithm:
Input- It should have one or more inputs.
Output –It should have one output.
Definiteness –Every step in an algorithm should be definite.
Finiteness- An algorithm consists of finite number of steps.
Effectiveness – An algorithm must be developed by using basic , simple , and feasible operations so
that one can trace it out by using just paper and pencil.

KEYWORDS USED IN ALGORITHM :

BEGIN, READ, INPUT, WRITE, OUTPUT, DISPLAY, END, GOTO, STEP


IF…….ELSE…….ENDIF

HOW TO WRITE ALGORITHM :

STEP-1 : BEGIN( START OF THE ALGORITHM)


STEP -2 : -----------------------
STEP -3 : -----------------------
--------------------
------------------------
STEP N : END (END OF THE ALGORITHM)

FLOW CHART OF ALGORITHM :

A flowchart is a pictorial representation of step by step solution of a problem.


Symbols used for flowcharts are :-
1. Terminal box- used to mark the beginning or end of the flowchart.

START STOP

2. Input / Output box – Input / Output of data.

INPUT/OUTPUT

3. Processing box – Any processing operations(arithmetic, Logical operations ) to be performed.

PROCESS
4. Decision box – Decision operation determines which of the alternative paths to be followed.

CONDITION

5. Flow Lines :- Joins two symbols and also represents the flow of execution.

KEYWORDS USED IN FLOWCHART :

Keywords which are generally used in flowchart are :


START, READ, INPUT, ACCEPT, WRITE, OUTPUT, DISPLAY, STOP, IF, Y FOR YES, N FOR NO

Example 1:
Write an algorithm& flowchart for addition of two numbers .
Step 1: Start
Step 2: Declare two variables A, B for storing the input.
Step 3: Read the first number and store it in ‘A’.
Step 4: Read the second number and store it in ‘B’.
Step 5: Declare a variable ‘SUM’ to store the total.
Step 6 : Add value stored in ‘A’ and ‘B’ and store the result in the variable ‘SUM’.
Step 7 : Display ‘SUM’. Flowchart
Step 8: Stop
START
Algorithm

Step 1 : BEGIN
Step 2 : READ A , B READ A & B

Step 3 : SUM = A + B
Step 4 : PRINT SUM SUM = A + B
Step 5 : END

WRITE SUM

STOP
Example 2:
Write an algorithm & flowchart for calculation of Simple Interest .
Step 1: Start
Step 2: Declare two variables P, T, R for storing the input.
Step 3: Declare a variable SI to store the Simple Interest.
Step 4: Calculate Simple Interest and store the result in SI.
SI = ( P × T × R)/100
Step 5: PRINT SI
Step 6 : Stop
Flowchart

START
Algorithm

Step 1 : BEGIN
Step 2 : READ P , T, R READ P T & R

Step 3 : SI = ( P × T× R)/100
Step 4 : PRINT SI SI= ( P × T× R)/100
Step 5 : END

WRITE SI

STOP

“IF” STATEMENT :

IF (Condition) THEN
Statement // Executes the Statement only if the condition is “True”
END IF
Example 3:
Write a check whether number is positive.
Algorithm :
Step 1: Begin
Step 2: Input number ‘N’
Step 3: IF N > 0 THEN
Display “Number is positive”
Step 4: END IF
Step 5: End
“IF-ELSE” STATEMENT :

IF (Condition) THEN
Statement // Executes the Statement only if the condition is “True”
ELSE
Statement // Executes the Statement only if the condition is “False”
END IF

Example 3:
Write a check whether number is positive.

Step 1: Begin
Step 2: Input number ‘N’
Step 3: IF N mod 2= 0 THEN
Display “Number is even”
Step 4: ELSE
Display “Number is odd”
Step 5: END IF
Step 6: End

“NESTED IF-ELSE” STATEMENT :

IF (Condition) THEN
Statement // Executes the Statement only if the condition is “True”
ELSE IF (Condition) THEN
Statement // Executes the Statement only if the condition of IF is “False”
ELSE
Statement // Executes the Statement only if the condition of IF & ELSE IF is “False”
Example 4:
Write a algorithm using nested if else to input marks and display the corresponding grade.

Step 1: Begin
Step 2: Input marks (an integer from 0 to 100)
Step 3: IF marks >=90
Display “Grade A”
Step 4: ELSE IF marks >=75
Display “Grade B”
Step 5: ELSE IF marks >=60
Display “Grade C”
Step 6: ELSE IF marks >=40
Display “Grade D”
Step 7: ELSE
Display “Grade F”
Step 7: END

NUMBER SYSTEM:

A number system is a system of representing numbers using digits or symbols . It allows us to


express, understand and perform operations with numbers in computing and mathematics.
Types of number systems :
There are four main types of number systems :
1. Binary number system
2. Decimal number system
3. Octal number system
4. Hexadecimal number system
Binary Number system:
 Base – 2
 Digits used : 0,1
 Used in computers and digital electronics
 Each digit is called Bit( Binary digit).
 Example : 1010 (binary) =10 (decimal)
Decimal Number system:
 Base – 10
 Digits used : 0,9
 Used in Every day life and general arithmetic
 Example : 275(decimal)
Octal Number system:
 Base – 8
 Digits used : 0,7
 Used in shorter representation of binary numbers (especially in early computing).
 Example : 57 (octal) =47 (decimal)
Hexadecimal Number system:
 Base – 16
 Digits used : 0-9 and A-F
 Used in programming ,memory addressing and color codes in HTML
 Example : 1F(Hex)= 31 (decimal)

Number System Conversions

1. Decimal to Other Systems

Decimal to Binary:

 Divide the decimal number by 2.

 Write down the remainder.

 Divide the quotient again by 2.

 Repeat until quotient is 0.

The binary number is the remainders read from bottom to top.

Example: Convert 13 to binary

 13 ÷ 2 = 6 remainder 1
 6 ÷ 2 = 3 remainder 0
 3 ÷ 2 = 1 remainder 1
 1 ÷ 2 = 0 remainder 1
 Binary = 1101

Decimal to Octal:

 Divide by 8 and write remainder.

 Repeat until quotient is 0.

 Octal number is remainders read bottom to top.

Example: 65 to octal

 65 ÷ 8 = 8 remainder 1
 8 ÷ 8 = 1 remainder 0
 1 ÷ 8 = 0 remainder 1
 Octal = 101
Decimal to Hexadecimal:

 Divide by 16 and write remainder (use A-F for 10-15).

 Repeat until quotient is 0.

 Hex number is remainders read bottom to top.

Example: 254 to hex

 254 ÷ 16 = 15 remainder 14 → F and E


 15 ÷ 16 = 0 remainder 15
 Hex = FE

2. Binary to Other Systems

Binary to Decimal:

Multiply each bit by 2 raised to the position index (from right, starting at 0). Sum all results.

Example: 1101 to decimal


= (1×2³) + (1×2²) + (0×2¹) + (1×2⁰) = 8 + 4 + 0 + 1 = 13

Binary to Octal:

Group binary digits into groups of 3 from right to left. Convert each group to its octal equivalent.

Example: 10101 to octal


Group as 010101 (add leading zeros to last group):
010 = 2, 101=5
Octal = 25

Binary to Hexadecimal:

Group binary digits into groups of 4 from right to left. Convert each group to its hex equivalent.

Example: 10111110 to hex


Group: 1011 1110
1011 = B, 1110 = E
Hex = BE
3. Octal to Other Systems

Octal to Decimal:

Multiply each digit by 8 raised to its position index. Sum the results.

Example: 57 (octal) to decimal


= (5×8¹) + (7×8⁰) = 40 + 7 = 47

Octal to Binary:

Convert each octal digit to 3-bit binary.

Example: 57 (octal)
5 = 101, 7 = 111
Binary = 101111

4. Hexadecimal to Other Systems

Hexadecimal to Decimal:

Multiply each digit by 16 raised to its position index. Sum all results.

Example: 1F (hex) to decimal


= (1×16¹) + (15×16⁰) = 16 + 15 = 31

Hexadecimal to Binary:

Convert each hex digit to 4-bit binary.

Example: 1F (hex)
1 = 0001, F = 1111
Binary = 00011111

Conversions to Decimal

1. Binary to Decimal

 Write the binary number.

 Assign powers of 2 to each bit from right to left, starting at 0.

 Multiply each bit by 2 raised to its power.

 Add all the results to get the decimal number.

Example: Convert binary 1011 to decimal


= (1×2³) + (0×2²) + (1×2¹) + (1×2⁰)
= 8 + 0 + 2 + 1 = 11
2. Octal to Decimal

 Write the octal number.

 Assign powers of 8 to each digit from right to left, starting at 0.

 Multiply each digit by 8 raised to its power.

 Add all the results to get the decimal number.

Example: Convert octal 345 to decimal


= (3×8²) + (4×8¹) + (5×8⁰)
= (3×64) + (4×8) + (5×1)
= 192 + 32 + 5 = 229
3. Hexadecimal to Decimal

 Write the hex number.

 Assign powers of 16 to each digit from right to left, starting at 0.

 Convert letters A-F to numbers (A=10, B=11, ..., F=15).

 Multiply each digit by 16 raised to its power.

 Add all the results to get the decimal number.

Example: Convert hex 2A3 to decimal


= (2×16²) + (10×16¹) + (3×16⁰)
= (2×256) + (10×16) + (3×1)
= 512 + 160 + 3 = 675

PRACTICE PROBLEMS:

1. Convert binary 11010 to decimal

2. Convert octal 127 to decimal

3. Convert hexadecimal 3C to decimal

4. Convert decimal 45 to binary

5. Convert decimal 100 to octal

6. Convert decimal 255 to hexadecimal

CONVERSION BETWEEN NUMBER SYSTEMS

a) Decimal to Binary

1. Convert 25 to binary.

2. Convert 100 to binary.


3. Convert 255 to binary.

b) Binary to Decimal

4. Convert 1010 to decimal.

5. Convert 11111111 to decimal.

6. Convert 10001 to decimal.

c) Decimal to Octal

7. Convert 64 to octal.

8. Convert 255 to octal.

9. Convert 73 to octal.

d) Octal to Decimal

10. Convert 100 to decimal.

11. Convert 77 to decimal.

12. Convert 145 to decimal.

e) Decimal to Hexadecimal

13. Convert 254 to hexadecimal.

14. Convert 1023 to hexadecimal.

15. Convert 16 to hexadecimal.

f) Hexadecimal to Decimal

16. Convert A3 to decimal.

17. Convert 1F to decimal.

18. Convert 7B to decimal.

BINARY ARITHMETIC:

Binary arithmetic is the process of performing arithmetic operations such as addition, subtraction,
multiplication, and division using the binary number system, which consists of only two digits: 0 and 1.
The data is represented and manipulated in binary form.
Basic Binary Arithmetic Operations:
1. Binary Addition : Binary addition is the process of adding two binary numbers. Binary addition uses only
two digits: 0 and 1.

Basic Rules of Binary Addition:


Binary Result Carry
Operation
0+0 0 0
0+1 1 0
1+0 1 0
1+1 0 1
1+1+1 1 1

Process of Binary Addition:


1. Start from the rightmost bit (least significant bit).
2. Add the corresponding bits of both numbers.
3. If the sum is greater than 1, carry is generated to the next left bit.
4. Continue adding each bit and carry until the end.

Step-by-Step Examples:
Example 1:
Add 1011 and 1101:
1 1 1 (Carries)
1011
+ 1101
-------
11000
Example 2:
Add 1001 and 0011:
1 (carry)
1001
+ 0011
-------
1100
Example 3:
Add 111 and 101:
11 (carry)
0111
+ 0101
-------
1100
2. Binary Subtraction
Binary subtraction is the process of subtracting one binary number from another where only two digits (0 and
1) are used.
Basic Rules of Binary Subtraction:

Binary Result Borrow


Operation
0−0 0 0
1−0 1 0
1−1 0 0
0−1 1 1 (borrow
from next
higher bit)

Borrowing in Binary Subtraction:


If you subtract 1 from 0, you need to borrow 1 from the next higher bit. In binary:
 Borrowing 1 from a bit is like borrowing 2 (10 in binary).
 So, 0 becomes 10 (2 in decimal) after borrowing.
 Then 10 - 1 = 1, and the remaining bit is adjusted accordingly.

Step-by-Step Examples:
Example 1:
Subtract 0110 (6 in decimal) from 1001 (9 in decimal):
1 (borrow)
1001
- 0110
-------
0011 (3 in decimal)
Example 2:
Subtract 0101 (5 in decimal) from 1100 (12 in decimal):
11 (borrows)
1100
- 0101
-------
0111 (7 in decimal)
Example 3:
Subtract 0011 (3 in decimal) from 1010 (10 in decimal):
11 (borrows)
1010
- 0011
-------
0111 (7 in decimal)

Key Points to Remember:


- Binary subtraction often involves borrowing.
- Borrowing in binary is like adding 2 (10 in binary) to the current bit.
- Always start subtraction from the rightmost bit.
3. Binary Multiplication
Rules of Binary Multiplication:
Binary Result
Operation
0×0 0
0×1 0
1×0 0
1×1 1
Process:
 Multiply each bit of the second number with the entire first number.
 Shift one position to the left for each new row (just like decimal multiplication).
 Add all the results.

Example:
101
× 11
-----
101
101
-----
1111
4. Binary Division
Rules of Binary Division:
 Similar to decimal division.
 Use repeated subtraction.
 The result includes quotient and remainder.

Process:
 Compare the divisor with the leftmost bits of the dividend.
 Subtract if possible, record 1 in quotient.
 If not, record 0 and bring down the next bit.

Example:
101010 ÷ 110
Binary Addition Q/A Binary Subtraction Q/A
1. 1010 + 1101 = 10111 1. 1101 − 1001 = 0100

2. 1001 + 0110 = 1111 2. 1010 − 0101 = 0101

3. 1111 + 0001 = 10000 3. 1111 − 0110 = 1001

4. 1011 + 1011 = 10110 4. 1000 − 0011 = 0101

5. 1100 + 0101 = 10001 5. 1100 − 1010 = 0010

6. 0110 + 0011 = 1001 6. 1011 − 0111 = 0100

7. 1000 + 1000 = 10000 7. 1110 − 1000 = 0110

8. 1110 + 1110 = 11100 8. 1001 − 1001 = 0000

You might also like