0% found this document useful (0 votes)
11 views42 pages

1 Unit-Basics of Programming

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)
11 views42 pages

1 Unit-Basics of Programming

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
You are on page 1/ 42

1|Page C Language Material by Girraj Sharma

UNIT1: BASICS TO LEARN A PROGRAMMING LANGUAGE

Covered Topics
 What is language?
 What is mean by programming language?
 What is the purpose of programming language?
 Types of programming language
 Low level language
 High level language
 What is C?
 Popular applications developed by using C
o popular os
o popular db
o popular language
 What is procedural oriented programming paradigm?
 What is the advantage of C is having procedural oriented language?
 What is mean by block structured programming?
 What is the advantage of C is having block structured language?
 What is program?
 Translator?
o compiler
o interpreter
o assembler
 What is the difference between compiler and interpreter?
 Source code
 Compile code
 Input vs Output
 Statement vs Program vs Software?
 Types of software
 What is bug/error in the program?
 Types of errors
 RAM vs HD vs CPU
 CPU architecture
 RAM architecture
 How to program going to be executed in the memory?
 Number System
 Types of Number system
 Number system conversion
1. Decimal to binary
2. Decimal to octal
3. Decimal to hexa-decimal
4. Binary to decimal
5. Octal to decimal
6. Hexa-decimal to decimal
7. Binary to octal
8. Octal to binary
9. Binary to hexa-decimal
10. Hexa decimal to binary
2|Page C Language Material by Girraj Sharma

11. Octal to hexa decimal


12. Hexa decimal to octal
 Decimal to any
 Any to Decimal
 Any to Any
 First 16 decimal, binary, octal, hexa decimal number table
 Direct binary to decimal conversion with the help of 2^n series
 Direct decimal to binary conversion with the help of 2^n series
 Binary Addition
 One's complement
 Two's complement
 Binary subtraction
 Signed vs Unsigned memory representation
 Positive decimal to binary 8bit represenation
 Positive decimal to binary 16bit represenation
 Negative decimal to binary 8bit represenation
 Negative decimal to binary 16bit represenation
 8bit Signed binary to decimal conversion
 16bit Signed binary to decimal conversion
 8 bit Unsigned binary to decimal conversion
 16 bit Unsigned binary to decimal conversion
 Range operations
o Signed range
 1bit
 2bit
 3bit
 4bit
 8bit
 16bit
 32bit
o unsigned range
 1bit
 2bit
 3bit
 4bit
 8bit
 16bit
 32bit
 Formula to calculate signed and unsigned range
 Binary number copy operation
o 8 bit to 16bit copy operation
 signed to signed copy
 signed to unsigned copy
 unsigned to signed copy
 unsigned to signed copy
o 16 bit to 8bit copy operation
 signed to signed copy
 signed to unsigned copy
3|Page C Language Material by Girraj Sharma

 unsigned to signed copy


 unsigned to signed copy
 More practices based on copy operations
o 3 bit to 5bit copy operation
 signed to signed copy
 signed to unsigned copy
 unsigned to signed copy
 unsigned to signed copy
o 5 bit to 3bit copy operation
 signed to signed copy
 signed to unsigned copy
 unsigned to signed copy
 unsigned to signed copy

 Bit operation practice using c program


 Required s/w for C
 Some popular C compiler
 16bit compiler vs 32bit compiler vs 64bit compiler
 Installing C compiler
 Commands and steps of Creating, compiling and executing C program
 Short cut key in turbo c compiler
o Alt+f9
o Ctrl+f9
o Alt+f5
o F7
 Stepwise Debugging C program
 How to using watch expression in TCC?
 History of C
 Characteristics of C
 Features of C
 Structure of C program
 Required header files
 Main() function
 Printf() vs scanf() function
 Clrscr() vs getch() function
 Developing first C program

Q: What is language?
Ans: Language is a common medium (understanding) by using which two person can communicate
with each other.
4|Page C Language Material by Girraj Sharma

In this diagram Person1 can‟t communicate to person2 using hindi because hindi is unknown to the
person2, similarly person2 can‟t communicate with person1 because English is unknown language to
the person1.

If two persons want to communicate with each other then there should be some common medium
between them in the form of language or communication can be happened with the help of translator.

After learning the English by the person1 then these persons can communication with each other
using English because English is common language for these persons.

There is another solution is that Person1 and Person2 should hire another person3 that are having a
knowledge of hindi and English both. In this communication person3 acts like a translator that can
translates the hindi instructions into English format, and English statement into hindi format.

Here hindi and English are human language it is not a programming language hence it can‟t be used
for programming purpose.

If any human person want to communicate with the computer then again some common medium is
required between the human person and computer. But computer doesnt know the meaning of human
language such as hindi, english etc.

Inside any computer machine all instructions are executed by the processor. And processor is a fastest
electronic device which can interpret only binary language (low level language). But as a human
being binary language is too difficult for learning us.

Consider the given diagram

In this diagram if we want to performing some work by the computer, then we need to sending our
requirement to the computer. If we are sending our requirement to the computer using hindi/English
the computer is not able to interpret that hindi or English instructions because computer doesn‟t
knowing the human language. Then what can we do, we are having four choices which is as given
5|Page C Language Material by Girraj Sharma

Choice1: As computer is knowing only the binary language if we are also learning the binary
language that we can send our requirement in binary format then computer can easily interpret our
binary instructions. But learning the binary language is too much difficult for us we can‟t learn easily
hence it is never recommended to learn the binary language (machine language).

Choice2: If computer will learn the human language (hindi, English) then also communication is
possible. But as we know computer is a machine computer is not a human that‟s what computer can‟t
learn anything.

Choice3: We should hire some another person as a translator that will know the human language as
well as binary language. So that using this person we can talk with the computer. But problem is that
there is no such person (translator) available in the market that can translate the human language into
the binary language.

Choice4: There some languages are available in the market that can be easily translated into binary
language by the translators, these languages are nothing but known as programming language ie. C,
C++, Java, .Net, Python etc. And these programming language can easily learn by us. If we will learn
any programming language then using these programming language we can talk (communicate) with
the computer.

After learning the programming language (C,C++) we can write our requirements (program) and these
programming language code will be converted into binary language by the translators(compiler) into
computer understandable code (binary language) and this code can be easily interpreted by the
processor.

Q: What is mean by programming language?


 Any language that can be use for programming purpose is known as programming language.
 Any language that can be translated into binary/machine code known as programming language.
 Any language by using which we can develop the software/program/applications known as
programming language.
Ex: C, C++, Java, .Net, PHP, Python etc

Q: What is the purpose of programming language?


 The main purpose of programming language is to develop the software that will makes our life is
very easier.
Ex1: Using banking application we can easily handle our account there is no need to visit the
branch of the bank physically
Ex2: Using ticket booking application we can book the bus, train, movie tickets easily from
anywhere
Ex3: Using online shopping application we can buy the required product easily
Ex4: Using calculator application we can perform any mathematical operation very fast.
6|Page C Language Material by Girraj Sharma

Types of programming language


1. Low level language
2. High level language

Low Level Language:


 Any language instructions that can be directly executed by the processor known as low level
language.
 It is machine understandable code.

High Level Language


 It is programmer understandable code, that can be executed by the processor after translation.
 In order to executing the high level language code by the computer we need to some translator
software that can translates the high level language code into machine code instructions.
Ex: C, C++, Java, Python…
Q: What is C?
C is a highly portable, block structured, procedural oriented, high level programming language.
 Highly portable: The source code of any programming language will giving the same
output/results in any compiler of that language known as portable code and underlying
programming language is known as portable language. C program is also giving the same results
in any C compiler therefore C language is also known as portable.
Note: C is partially portable, it is not 100% portable.
 Block structured: If any language is allow to create the block inside a function known as block
structured programming language. By creating the blocks we can control the scope and life of the
variables so the memory can be used efficiently.
 Procedural oriented: If any programming language is allowing to creates the function or
procedures known as procedural oriented language. The main purpose of procedural oriented
language is code reusability.
 High level language: It is human understandable language, it can be easily learn by the
programmer. High level languages are using English words as their source code.

Popular applications developed by using C


 As we know unix is the most popular and secured OS which is developed by using C language.
 As we know JAVA is most popular programming language for developing the enterprise
application, which is also developed by using C language.
 ORACLE is most popular DBMS based database software which is also developed by using C
and C code.
 Most of popular Compilers, OS, device drivers developed by using C language.

Q: What is procedural oriented programming paradigm?


 Procedural oriented is a concept or programming principles that is used for developing
programming language.
 Based on this programming principal we can divide the big problem into small-small modules and
these modules are nothing but known as procedure or functions.

Q: What is the advantage of C is having procedural oriented language?


 The main advantage of procedural oriented language is to reuse the code.
7|Page C Language Material by Girraj Sharma

Q: What is mean by block structured programming?


 Any programming language which is allow to create the blocks known as block structured
programming language
Example:
fun()
{
statements;
{
block-1;
}
{
block-2;
}
More statements
}

Q: What is the advantage of C is having block structured language?


 By creating the small blocks we can control the access permission (scope) of the local variables
and also can control the life of the variable so that the memory can be used efficiently.

Q: What is program?
 Program is a group of related statements which will going to be provide the solution of real word
problem
Ex: To perform the addition, calculating simple interest, transferring the balance from one
account to another bank account, converting temperature Fahrenheit to Celsius and Celsius to
Fahrenheit.

Q: What is translator?
 Any software that can translates the high level language code into low level language code known
as translator.
 In order to running the program of any high level language by the computer, program should be
converted into computer (hardware) understandable format (machine code/binary code). For this
translation purpose we have required some software that is nothing but translators.
 The main role of translator is
a. Check the syntaxes of the program, if any syntactical mistake is doing by the programmer
then translator will not compile the program.
b. If program is syntactically correct then translator will translates program into low level format

There are three types of translators


1. Compiler
2. Interpreter
3. Assembler
Compiler:
 Compiler reads and check the entire program completely and if any errors in the program then
compiler will be reporting the all error message without doing any translation. If code is
syntactically correct then the whole code translated into low level format, and that low level
instructions are ready for execution.
 Compiler will translates the any program into the machine code format in a single step.
8|Page C Language Material by Girraj Sharma

Interpreter:
 Interpreter will perform the code translation statement by statement. It will translate only one
statement at a time. After translating the current statement then only next statement is going to be
translated by the interpreter.
 Interpreter will checks the syntax and translate the code into low level format statement by
statement. After translating the current statement then interpreter will checks the syntax of next
statement and will translates into machine code format and same process is applied for the all
statements. Since compiler will translates only one statement at a time therefore it can show only
single error message at a time. After correcting the current error message then only we are able to
check the next error.
Assembler:
 Assembler will be used to translate the assembly language code into the low level language.

Q: What is the difference between compiler and interpreter?


Compiler Interpreter

1. It will not performs statement by It will performs statement by statement


statement translation translation
2. Can reports all the error message At a time interpreter can report only single error
simultaneously message. It will reporting all error message one
by one not simultaneously
3. Relatively translation speed is fast Relatively translation speed is slow, because it
will performs the translation statement-by-
statement.

Q: What is source code?


 Anything written by the programmer using the programming language is known as source code.
 As a programmer we are responsible for writing the source code.

Q: What is compile code?


 After compilation whatever the code generated by the compiler known as compile code.
 Being a programmer we are not responsible for creating the compile code. Compiler is
responsible for generating the compile code.

Q: What is input?
 During execution any data or values receiving/taken by the program from another
device(keyboard) known as input to the program
Ex: Entering password and withdrawal amount using ATM machine, entering username and
password in the gmail account, entering two numbers for addition etc.

In an addition program:-
Enter first number: 10
Enter second number: 20
In this example the number 10 and 20 are the inputs for the program

Q: What is output?
 During execution any data/values send by the program to the another device(monitor) known as
output of the program.
9|Page C Language Material by Girraj Sharma

In an addition program:-
Enter first number: 10
Enter second number: 20
Result is 30
In this example 30 is the output of this program
Statement vs Program vs Software:
Statement: statement is separated by using semicolon, statement is a line in the program which ended
by the semicolon.
Ex:
Statement1;
Statement2;

Statement-n;
Any statement can be divided into many lines.
Ex:
int x = 10; is a statatment which can be written into multiple lines in given way
int
x
=
10;
In a single line we can place multiple statements
int x = 10; clrscr(); printf(“%d”,x);
In this line there are three statements

Program:
 Program is a collection of related statements which is going to be provide a solution of single
problem.
Ex: program that will performs the addition of two numbers containing three statements. These
three statement will performs the addition of two numbers
int add(int x,int y)
{
int res;
res = x + y;
return res;
}

Software:
 Software is a collection of related programs

 In this example there are four programs, program1 for addition, program2 for subtraction,
program3 for subtraction, program4 for division and these all programs together forms a
calculator software. In this example each program contains three statements and these three
statements together performs a single arithmetic operations etc.
10 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

Types of software:

There are two types of software system software and application software, C language is most popular
for developing system software. ie Compiler, Operating system, device drivers, Anti-virus

Q: What is error?
 Error is bug in the program which may terminating the execution of program abnormally.
 Any unknown (invalid) statement in the program is nothing but error.
 Any statement in the program which is against the rule of compiler is nothing but error.
 Abnormal behaviour of the program is nothing but error.
 Whenever any program is crashed during the execution is nothing but error.
 Whenever any program is giving the unexpected results is nothing but error.

Types of errors:
11 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

There are four types of errors can be seen in the C program


1. Syntax error or compiletime error
2. Runtime error
3. Linker error
4. Logical error (Most dangerous)

Syntax error:
Any error message which is raised by the compiler during compilation known as syntax error or
compiletime error.

It is syntactical mistake in the program, Any statement is violating the rules of the C compiler is
known as syntax error. These errors are reported by the compiler at compiletime therefore it is also
known as compiletime error.

Compiletime errors can be traced by looking into the source code of the program. Syntax errors also
known as static errors.

If we are able to find out the error based on source code such type of error is known as static error or
compiletime error.
Runtime Error:
Any error message which is given by the operating system due to wrong input given by user is known
as runtime error.

The main cause of runtime error is wrong input provided by the user or required resource(file) not
available.

Runtime error might not be traced based on source code. Because its behaviour completely depends
upon runtime input
Ex: dividing any number by the zero, file not found, calculating the square root of negative numbers
etc.

Linker Error:
Any error raised by the linker at the time of linking phase known as linker error.
The main cause of linker errors are definition of any variable or function is not found at the time of
linking phase.
If variable and function declaration is available but definition is not found then in this case linker will
gives an error during linking phase of the program
Note: We will discussing linker errors later in details

Logical Error:
It is the logical mistakes done by the programmer in the code, in case of logical error our program will
compile and run successfully but not giving the expected results.
It is most dangerous in the program. We should take care about the logical error seriously.

Hard-Disk vs RAM vs CPU:


Hard-Disk:
 HD is a memory that can store the data permanently for long time.
 HD is also known as persistence storage device.
12 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

 HD is a physical device but we can divide a HD memory into any number of logical partitions in
the form of drives (disk volume).
 All files and installed software (including OS) will store inside HD memory permanently.
 The source file and executable file of C program also will be stored inside HD memory.

Q: what is the purpose of creating logical partition of HD memory?


 HD can store large volume of data if we are storing the whole data as a single partition in the hd
then it is very difficult to manage the data.
Ex: if we want to search a required file then these file might be searches in the entire HD memory
which may increases the search time. Due to above reason there may be chance of the
performance of the system going to be down. In order to improving the performance of the system
we should store the data category wise in a separate drives.
If we are managing the data category wise into a separate drives then whenever any file is needed
then we need to search a required file only a single related drive there is no need of search this file
into the entire HD memory.

 In the below diagram HD memory is logically divided into C,D,E …drives. If we need search an
image file the we can apply the search operation only on the E:\ dirve there is no need of
searching in the remaining drives.

RAM:
 RAM is a physical device that can store the data temporary during execution of the program.
 All running application will be available inside a RAM memory.
 To run any application by the processor with the help of OS required applications will be loaded
from HD to RAM memory.
 Processor always takes the required executable instructions directly from the RAM memory only,
Processor will not communicate with the HD memory directly. Because the read/write speed of
HD memory is to slow as compare to RAM. RAM memory will provides fast access of data to the
processor.
 In order to improve the performance before running any application OS will loads this application
(program) from HD to RAM memory.
 RAM is also physical device, it is also divided into multipal logical partitions to manage the data
category wise in the form of variables.
ie. Data area, heap area, method area, stack area.
13 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

Note: We will discussing about logical partition of the RAM later in details.
 All global variables and static variables will be created inside data area
 All dynamic memory allocations are performed inside heap
 Before execution the compile code of any program will be loaded from HD to RAM memory
inside method area.
 All local variables (auto variables) will be created inside stack area

CPU (Central Processing Unit) or Processor:


 In a computer the whole instructions of the program will be executed by the processor only.
 CPU is connected with the RAM memory there is no direct connection available between HD and
processor.
 Processor is a fastest electronic device. As we know all electronic devices are using the power
supply in the form of volts. Processor will also takes the all executable instructions in the form of
volts.
 Volts has only two states On and Off. These two states of the power will supplied to the processor
in the form of digital format 1 and 0.
 1 means on, and 0 means off. Sending a 1 to the processor means sending +5Volts. Sending a 0 to
the processor means sending 0volts.
 Processor can process any code only in the form of 0 and 1.
 Any instruction which is written by using 0 and 1 (two binary digits) known as binary language.
Since these binary language is interpreted by the machine (processor) therefore binary language
also known as machine code instructions or low level language.
Processor is a physical device which is also divided into three logical partitions.
1. ALU (Arithmetic Logic Unit)
2. CU (Control Unit)
3. CPU Registers (Memory inside processor chip)

Number System
 Number system is way representing any number in different-different types.

Types of Number system


14 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

 There are four types popular number systems are available that is supported by the computer
a. Binary number system or Base 2 number system
b. Octal number system or Base 8 number system
c. Decimal number system or Base 10 number system
d. Hexa-Decimal number system or Base 16 number system
Binary number system:
 In the binary number system there two distinct digits are allowed 0 and 1 only. Therefore it is also
known as base2 number system
 At memory level any information will be stored in the form of binary number system

Octal number system:


 This number system is using 8 distinct digits 01234567, therefore it is also known as base8
number system.
Decimal number system:
 This number system is using 10 distinct digits 0123456789, therefore it is also known as base 10
number system.
 In a daily life any human person is using decimal number system.

Hexa-Decimal number system:


 This number system is using 16 distinct digits 0123456789ABCDEF, therefore it is also known as
base 16 number system.

Number system conversions:

Decimal to binary conversion:


In this type of conversion given decimal number will be divided by 2 till the quotient comes as 0 or 1
(less than 2), and collect the all reminder comes after the each division operations in reverse order
(bottom to top order)
For more clarity consider the given example:
Example: (13)10 = (?)2
Step1: divide the decimal number 13 by the binary base 2 and collect the quotient and reminder
separately.

Step2: Divide the resultant quotient(6) by 2 again

Step3: Divide the resultant quotient(3) by 2 again


2) 3 ( 1
-2
-----
1
15 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

Step4: After dividing the resultant quotient(1) by 2 again we get the reminder as 1
Step5: Collect all the reminder together in order of step4, step3, step2, step1
Ans: 1 1 0 1

(13)10 = (1101)2
Example2: (25)10 = ( ? )2

Example3: (93)10 = ( ? )2

Practice: Fill the equivalent binary number in the blanks


(10)10 = ( __________________________________ )2
(7)10 = ( __________________________________ )2
(15)10 = ( __________________________________ )2
(27)10 = ( __________________________________ )2
(65)10 = ( __________________________________ )2
(63)10 = ( __________________________________ )2
(64)10 = ( __________________________________ )2
(127)10 = ( __________________________________ )2
(255)10 = ( __________________________________ )2
(260)10 = ( __________________________________ )2
(1)10 = ( __________________________________ )2
(2)10 = ( __________________________________ )2
(4)10 = ( __________________________________ )2
(8)10 = ( __________________________________ )2
(16)10 = ( __________________________________ )2
(32)10 = ( __________________________________ )2
(64)10 = ( __________________________________ )2
(128)10 = ( __________________________________ )2
(256)10 = ( __________________________________ )2
16 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

(512)10 = ( __________________________________ )2
(1024)10 = ( __________________________________ )2
(275)10 = ( __________________________________ )2
(369)10 = ( __________________________________ )2
(32767)10 = ( __________________________________ )2
(32768)10 = ( __________________________________ )2
(65536)10 = ( __________________________________ )2
(65535)10 = ( __________________________________ )2

Note: Before solving these practice questions you should practice the previous solved example1,
example2, example3 for the reference purpose

Practice: Match the decimal number to its equivalent binary number.


Decimal no Binary no
25 10010
128 11111111
18 10000000
127 11001
255 1111111
Practice: Match the decimal number to its equivalent binary number.
Decimal no Binary no
350 100101010110
325 101011110
2004 100101111010
2390 101100011
2426 11111010100
Decimal to octal conversion:
In this type of conversion given decimal number will be divided by 8 (octal base) till the quotient is
more than 8(divisor), and collect the all reminder comes after the each division operations in reverse
order (bottom to top order).

For more clarity consider the given example:


Example: (75)10 = (?)8
Step1: divide the decimal number 75 by the octal base 8 and collect the quotient and reminder
separately.

Step2: Divide the resultant quotient(9) by 8 again

Now the reminder comes 1, so need to divide again


17 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

Step3: Collect all the reminder together in reverse order bottom to top order
Ans: 1 1 3

Final result is (75)10 = ( 1 1 3)8

Example2: (100)10 = ( ? )8

Example3: (165)10 = ( ? )8

Practice: Fill the equivalent OCTAL number in the blanks


(10)10 = ( _______________ )8
(7)10 = ( _______________ )8
(15)10 = ( _______________ )8
(27)10 = ( _______________ )8
(65)10 = ( _______________ )8
(63)10 = ( _______________ )8
(64)10 = ( _______________ )8
(127)10 = ( _______________ )8
(255)10 = ( _______________ )8
(260)10 = ( _______________ )8
(1)10 = ( _______________ )8
(2)10 = ( _______________ )8
(4)10 = ( _______________ )8
(8)10 = ( _______________ )8
(16)10 = ( _______________ )8
(32)10 = ( _______________ )8
(64)10 = ( _______________ )8
(128)10 = ( _______________ )8
(256)10 = ( _______________ )8
(512)10 = ( _______________ )8
(1024)10 = ( _______________ )8
(275)10 = ( _______________ )8
(369)10 = ( _______________ )8
(32767)10 = ( _______________ )8
(32768)10 = ( _______________ )8
18 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

(65536)10 = ( _______________ )8
(65535)10 = ( _______________ )8
Practice: Match the decimal number to its equivalent octal number.
Decimal no octal no
25 377
128 177
18 31
127 200
255 22
Practice: Match the decimal number to its equivalent octal number.
Decimal no Octal no
350 4572
325 4526
2004 505
2390 3724
2426 536

Decimal to Hexa-Decimal conversion:


In this type of conversion given decimal number will be divided by 16 (Hexa-decimal base) till the
quotient is more than 16(divisor), and collect all the reminder comes after the each division operations
in reverse order (bottom to top order).
Allowed digits in hexa-decimal numbers are: 0 1 2 3 4 5 6 7 8 9 A B C D E F

After dividing the decimal number by 16 if the reminder will be in the range of 10 to 15 then it is
replaced by the hexa-decimal digits A to F.
Mapping table
A - 10
B - 11
C - 12
D - 13
E - 14
F - 15
Reminder 10 would be replaced by A, 11 replaced by the B, 12 replaced by the C, 13 replaced by the
D, 14 replaced by the E and 15 replaced by the F.

For more clarity consider the given example:


Example: (30)10 = ( ? )16
Step1: Divide the decimal number 30 by the hexa-decimal base 16 and collect the quotient and
reminder separately.
19 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

After dividing the decimal number 30 by the hexa-decimal base 16 we get the reminder as 14 and
according to mapping 14 should be replaced by the E. In this example we need not to be divide the 14
again by 16 because reminder 14 is already less than of 16.

Example2: (2045)10 = ( ? )16

Practice: Fill the equivalent hexa-decimal number in the blanks


(7)10 = ( ________)16
(15)10 = ( ________)16
(27)10 = ( ________)16
(65)10 = ( ________)16
(63)10 = ( ________)16
(64)10 = ( ________)16
(127)10 = ( ________)16
(255)10 = ( ________)16
(260)10 = ( ________)16
(275)10 = ( ________)16
(369)10 = ( ________)16
(32767)10 = ( ________)16
(32768)10 = ( ________)16
(65536)10 = ( ________)16
(65535)10 = ( ________)16
Practice: Match the decimal number to its equivalent hexa decimal number.
Decimal no Hexa-Decimal no
25 19
128 12
18 ff
127 7f
255 80
Practice: Match the decimal number to its equivalent octal number.
Decimal no Hexa-Decimal no
350 97a
325 15e
2004 145
2390 956
2426 7d4

Binary to decimal conversion:


 As we know base of binary number is 2, and base of decimal number is 10.
20 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

Step1: Write the all binary digits in the form of summation


Dn+…..D4+D3+D2+D1

Step2: Multiply each binary digits from right to left in terms of 2p in the given way
Dn*2n-1 +…..D4*23+D3*22+D2*21+D1*20

Step3: And solve the final expression of step2 and you will get the decimal number which is
equivalent of given binary number.
Example1: (1101)2 = ( ? )10
Step1: 1 + 1 + 0 + 1
Step2: 1*23 + 1*22 + 0*21 + 1*20
Step3: 1*8 + 1*4 + 0*2 + 1*1
8 + 4 + 0 + 1 = 13
(1101)2 = ( 13 )10

Example2: (10111)2 = ( ? )10


Step1: 1 + 0 + 1 + 1 + 1
Step2: 1*24 + 0*23 + 1*22 + 1*21 + 1*20
Step3: 1*16 + 0*8 + 1*4 + 1*2 + 1*1
16 + 0 + 4 + 2 + 1
(10111)2 = ( 23 )10

Example3: (110101)2 = ( ? )10


Step1: 1 + 1 + 0 + 1 + 0 + 1
Step2: 1*25 + 1*24 + 0*23 + 1*22 + 0*21 + 1*20
Step3: 1*32 + 1*16 + 0*8 + 1*4 + 0*2 + 1*1
32 + 16 + 0 + 4 + 0 + 1
(110101)2 = ( 53 )10
Example4: (101121)2 = ( ? )10
 101121 is an invalid binary number, because allowed digits for any binary numbers are 0 and 1
only, but in this number 2 is an invalid binary digit. So no need to convert into decimal.

Practice1: Convert the given binary numbers into the decimal and fill in the blanks
(1)2 = (________ )10
(10)2 = (________)10
(100)2 = (________)10
(1000)2 = (________)10
(10000)2 = (________)10
(100000)2 = (________)10
(1000000)2 = (________ )10
(10000000)2 = (________)10
(11)2 = (________)10
(111)2 = (________)10
(1111)2 = (________)10
(11111)2 = (________)10
(111111)2 = (________ )10
(1111111)2 = (________)10
(11111111)2 = (________)10
21 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

Practice2: Convert the given binary numbers into the decimal and fill in the blanks
(1010)2 = (________)10
(1101)2 = (________)10
(1111)2 = (________)10
(101101)2 = (________)10
(10000)2 = (________)10
(11111)2 = (________)10
(1000000)2 = (________)10
(111111)2 = (________)10
(10000000)2 = (________)10
(1111111)2 = (________)10
(11111111)2 = (________)10
(100000000)2 = (________)10
(10101011)2 = (________)10
(1000000000000000)2 = (________ )10
(111111111111111)2 = (________)10
(1111111111111111)2 = (________)10
(250)2 = (________)10
(12345)2 = (________ )10

Practice: Match the binary number to its equivalent decimal number.


Binary no Decimal no
110110101 257
111111111 411
101001010 437
100000001 330
110011011 511
Practice: Match the binary number to its equivalent decimal number.
Binary no Decimal no
10101 22
11011 24
10111 23
11000 21
10110 27
Octal to decimal conversion:
 As we know base of octal number is 8, and base of decimal number is 10.
Step1: Write all the octal digits in the form of summation
Dn+…..D4+D3+D2+D1

Step2: Multiply each octal digit from right to left in terms of 8p in the given way
Dn*8n-1 +…..D4*83+D3*82+D2*81+D1*80

Step3: And solve the final expression of step2 and you will get the decimal number which is
equivalent to the given octal number.
Example1: (253)8 = ( ? )10
Step1: 2 + 5 + 3
Step2: 2*82 +5*81 + 3*80
22 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

Step3: 2*64 + 5*8 + 3*1


128 + 4 0 + 3 = 171
(253)8 = ( 171 )10

Example2: (2345)8 = ( ? )10


Step1: 2 + 3 + 4 + 5
Step2: 2*83 +3*82 + 4*81 + 5*80
Step3: 2*512 + 3*64 + 4*8 + 5*1
1024 + 192 + 32 + 5 = 1253
(2345)8 = ( 1253 )10

Example3: (42035)8 = ( ? )10


Step1: 4 + 2 + 0 + 3 + 5
Step2: 4*84 + 2*83 +0*82 + 3*81 + 5*80
Step3: 4*4096 + 2*512 + 0*64 + 3*8 + 5*1
16384 + 1024 + 0 + 24 + 5 = 17437
(42035)8 = (17437)10

Example4: (280)8 = ( ? )10


 280 is an invalid octal number, because octal has allowed only 0 to 7 digits, but in this number 8
is an invalid octal digit. So no need to convert into decimal.

Practice: Convert the given binary numbers into the decimal and fill in the blanks
(10)8 = ( _____________)10
(125)8 = ( _____________)10
(520)8 = ( _____________)10
(728)8 = ( _____________)10
(2409)8 = ( _____________)10
(1234)8 = ( _____________)10
(242)8 = ( _____________)10
(5000)8 = ( _____________)10
(5030)8 = ( _____________)10
(42322)8 = ( _____________)10
(23252)8 = ( _____________)10
(20238)8 = ( _____________)10
(9353)8 = ( _____________)10
(10)8 = ( _____________)10
(10)8 = ( _____________)10
(10)8 = ( _____________)10
Practice: Match the octal number to its equivalent decimal number.
Octal no Decimal no
423 275
6343 3299
346 3822
7356 230
3467 1847

Hexa-decimal to decimal conversion:


23 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

 As we know base of hexa decimal number is 16, and base of decimal number is 10.
Step1: Write all the hexa decimal digits in the form of summation, Alphabetical digits(ABCDEF)
should replaced by the corresponding digits positionally. Positional digits of A is 10, B is 11, C is
12, D is 13, E is 14 and F is 15.

Dn+…..D4+D3+D2+D1

Step2: Multiply each hex digit from right to left in terms of 16p in the given way
Dn*16n-1 +…..D4*163+D3*162+D2*161+D1*160

Step3: And solve the final expression of step2 and you will get the decimal number which is
equivalent to the given hexa decimal number.

Example1: (253)16 = ( ? )10


Step1: 2 + 5 + 3
Step2: 2*162 +5*161 + 3*160
Step3: 2*256 + 5*16 + 3*1
512 + 80 + 3 = 595
(253)16 = ( 595)10

Example2: (2DF)16 = ( ? )10


Note: Use positional value of D as 13 and F as 15
Step1: 2 + D + F
2 + 13 + 15
Step2: 2*162 +13*161 + 15*160
Step3: 2*256 + 13*16 + 15*1
512 + 208 + 15 = 735
(2DF)16 = ( 735)10

Example3: (FACE)16 = ( ? )10


Note: Use positional value of F as 15,A as 10,C as 12, E as 14
Step1: F + A + C + E
15 + 10 + 12 + 14
Step2: 15*163 + 10*162 + 12*161 + 14*160
Step3: 15*4096 + 10*256 + 12*16 + 14*1
61440 + 2560 + 192 + 14 = 64206
(FACE)16 = (64206)10

Example4: (5CT9)16 = ( ? )10


 5CT9 is an invalid hexa decimal number, because hexa decimal has allowed only 0 to 9 digits and
A to F (a to f) alphabets, but in this number T is an invalid hexa decimal digit. So no need to
convert into decimal.

Practice: Convert the given hexa decimal numbers into the decimal and fill in the blanks
(24)16 = (_______________)10
(48)16 = ( _______________)10
(89)16 = ( _______________)10
(4D)16 = ( _______________)10
24 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

(2AF)16 = ( _______________)10
(B15)16 = ( _______________)10
(3214)16 = ( _______________)10
(abcd)16 = ( _______________)10
(29E)16 = ( _______________)10
(5232)16 = ( _______________)10
(23ED)16 = ( _______________)10
(512)16 = ( _______________)10
(42GD)16 = ( _______________)10
(2F5G)16 = ( _______________)10

Practice: Match the hexa decimal number to its equivalent decimal number.
Hexa-Decimal Decimal
423 838
6343 1059
346 29526
7356 25411
3467 13415

Binary to octal
 As we know base of binary number is 2, and the base of octal number is 8
 We can convert the any binary number into the octal number by using two methods.
a. Indirect method (Binary to decimal, Decimal to octal)
b. Direct method (Binary to octal)
Binary to octal conversion using indirect method:
 In this method two level conversion is required, first we should convert the binary into decimal
number, and then resultant decimal number should be converted into octal
Step1: Binary to Decimal
Step2: Decimal to Octal

Example1: (11010)2 = ( ? )8
Step1: Binary to decimal
(11010)2 = ( ? )10
1+1+0+1+0
1*24 + 1*23 + 0*22 + 1*21 + 0*20
1*16 + 1*8 + 0*4 + 1*2 + 0*1
16 + 8 + 0 + 2 + 0 = (26)10
Step2: Decimal to octal
( 26 )10 = ( ? )8

Final result is:


(11010)2 = ( 32 )8

Note: This method is too lengthy process of binary to octal conversion, therefore recommended to use
direct method.
25 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

Binary to octal conversion using direct method:


 In this method we can convert any binary number directly to its equivalent octal number with the
help of given table.

First eight octal number with their binary conversion


Distinct Octal Equivalent Binary
Digits Number
0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111
 As we seen in this table any octal digits can be made by using three binary digits. So in this
process of binary to octal conversion follow the given steps.
Step1: Create the three digits group of given binary number from right to left order
Bn.......... B8 B7 B6 B4 B3 B2 B1 B0
Bn.......... B8 B7 B6 B4 B3 B2 B1 B0

Step2: Replace the each group of three digits binary number by the equivalent octal digit
respectively.

Step3: And collect all octal digits together which is the final octal number for the given binary
number.
(Bn……B8 B7 B6 B4 B3 B2 B1 B0) = (On…..O2 O1 O0)

Example1: (111010)2 = ( ? )8
Step1: Create three digits group of this binary number
111 010
Step2: Replace each group of three digit binary number by the equivalent octal digit according to
previous table.
Octal digit of 111 is 7, octal digit of 010 is 2

Step3: (111010)2 = (72)8

Example2: (10110111010)2 = ( ? )8
Sol: ( 10 110 111 010)
2 6 7 2
(10110111010)2 = (2 6 7 2)8
Example3: (11011101011110110111010)2 = ( ? )8
Solve: 011 011 101 011 110 110 111 010
3 3 5 3 6 6 7 2
26 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

(11011101011110110111010)2 = (3 3 5 3 6 6 7 2 )8
Practice: Convert the given binary numbers into the equivalent octal and fill in the blanks
(11111111)2 = (_________________________)8
(100000000)2 = (_________________________)8
(1010101011)2 = (_________________________)8
(110110101011)2 = (_________________________)8
(100000000101)2 = (_________________________)8
(1101101101101100)2 = (_________________________)8
(101111100011)2 = (_________________________)8
(1110000010111011)2 = (_________________________)8
(110000011101101)2 = (_________________________)8
(10000110101010111)2 = (_________________________)8
(10101011111)2 = (_________________________)8
(11000000111111)2 = (_________________________)8
(101010101)2 = (_________________________)8
(1111111111111111)2 = (_________________________)8
(1111000011110000)2 = (_________________________)8
(110011001100110011)2 = (_________________________)8
Note: Recommended to use method2

Practice: Match the binary number to its equivalent octal number.


Binary Octal
10101100110 3145
11110000110 2706
10001110110 3606
11001100101 2166
10111000110 2546

Octal to Binary conversion:


 Any octal number can be converted into the binary number in two way
1. Using two level conversion (Indirect method)
In this approach convert the octal number into the decimal number, and again convert the
resultant decimal number into the binary.
Example: (4025)8 = ( ? )2
(4025)8 = ( ? )10 = ( ? )2
2. Octal to binary (Direct method)
In this way replace the each octal digits by the 3digit binary number.

Example1: (4025)8 = ( ? )2
Sol: 4 0 2 5
Replace all the octal digits by the binary number, write the binary in three bits for each octal
digits.
In three bits binary number of octal digit 4 is 100, binary number of octal digit 0 is 000,
binary number of octal digit 2 is 010, binary number of octal digit 5 is 101
4 0 2 5
100 000 010 101
(4025)8 = (100000010101)2
27 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

Example2: (543021)8 = ( ? )2
Sol: Replace each digit by three bit binary number
5 by 101, 4 by 100, 3 by 011, 0 by 000, 2 by 010, 1 by 001
5 4 3 0 2 1
101 100 011 000 010 001
(543021)8 = (101100011000010001)2

Example3: (703040501)8 = ( ? )2
Sol: Replace each digit by three bit binary number
7 0 3 0 4 0 5 0 1
111 000 011 000 100 000 101 000 001
(703040501)8 = (111000011000100000101000001)2
Example4: (2570)8 = ( ? )2
Sol: Replace each digit by three bit binary number
2 5 7 0
010 101 111 000
Note: Write the binary number after removing all the occurrences of starting 0 from the final
binary result.
(2570)8 = (10101111000)2
Example5: (4895)8 = ( ? )2
Sol: The number 4895 is an invalid octal number because digits 8 and 9 is not allowed in
octal representation the allowed digits are between 0 to 7 only.

Practice: Convert the given octal numbers into the equivalent binary and fill in the blanks
(352343)8 = (_______________________________________)2
(5000)8 = (_______________________________________)2
(250)8 = (_______________________________________)2
(324653)8 = (_______________________________________)2
(634323)8 = (_______________________________________)2
(2343646)8 = (_______________________________________)2
(777222)8 = (_______________________________________)2
(72727)8 = (_______________________________________)2
(57235)8 = (_______________________________________)2
(745424)8 = (_______________________________________)2
(177777)8 = (_______________________________________)2
(5342634)8 = (_______________________________________)2
(6524225)8 = (_______________________________________)2
(6342424)8 = (_______________________________________)2
(72225)8 = (_______________________________________)2

Practice: Match the binary number to its equivalent octal number.


Octal Binary
3145 10101100110
2706 11110000110
3606 10001110110
2166 11001100101
2546 10111000110
28 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

Binary to Hexa-Decimal
 As we know base of binary number is 2, and the base of hexa decimal number is 16
 We can convert the any binary number into the hexa decimal number by using two methods.
c. Indirect method (Binary to decimal, Decimal to Hexa-decimal)
d. Direct method (Binary to Hexa-decimal)
Binary to hexa-decimal conversion using indirect method:
 In this method two level conversion is required, first we should convert the binary into decimal
number, and then resultant decimal number should be converted into hexa-decimal.
Step1: Binary to Decimal
Step2: Decimal to Hexa-decimal

Example1: (11010)2 = ( ? )16


Step1: Binary to decimal
(11010)2 = ( ? )10
1+1+0+1+0
1*24 + 1*23 + 0*22 + 1*21 + 0*20
1*16 + 1*8 + 0*4 + 1*2 + 0*1
16 + 8 + 0 + 2 + 0 = (26)10
Step2: Decimal to hexa-decimal
( 26 )10 = ( ? )16

Final result is:


(11010)2 = ( 1 A )16

Note: This method is too lengthy process of binary to hexa-decimal conversion, therefore
recommended to use direct method.

Binary to hexa decimal conversion using direct method:


 In this method we can convert any binary number directly to its equivalent hexa-decimal number
with the help of given table.

First sixteen hexa-decimal number with their binary conversion


Distinct Hexa Equivalent
Decimal Digits Binary Number
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
A 1010
B 1011
C 1100
D 1101
29 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

E 1110
F 1111
 As we seen in this table any hexa decimal digits can be made by using four binary digits. So in
this process of binary to hexa decimal conversion follow the given steps. Any hexa-decimal digit
will takes maximum four binary digits therefore in this process any hexa-decimal digit will be
formed by using pair of four binary digits
Step1: Create the four digits (bits) group of given binary number from right to left order
Bn.......... B8 B7 B6 B4 B3 B2 B1 B0
Bn.......... B8 B7B6 B4 B3 B2 B1 B0

Step2: Replace the each group of four digits binary number by the equivalent hexa decimal digit
respectively.

Step3: And collect all hexa digits together which is the final hexa decimal number for the given
binary
number.
(Bn…..B8 B7 B6 B4 B3 B2 B1 B0) = (Hn….H1 H0)

Example1: (111010)2 = ( ? )16


Step1: Create four digits group of this binary number
11 1010 can be written like that 0011 1010
Step2: Replace each group of four digit binary number by the equivalent hex digit according to
previous table.
Hex digit of 0011 is 3, octal digit of 1010 is A

Step3: (111010)2 = (3A)16

Example2: (10110111010)2 = ( ? )16


Sol: (0101 1011 1010)
5 B A
(10110111010)2 = (5 B A)16
Example3: (11011101011110110111010)2 = ( 5 B A )16
Solve: 0110 1110 1011 1101 1011 1010
6 E B D B A
(11011101011110110111010)2 = (6EBDBA)16
Practice: Convert the given binary numbers into the equivalent hexa-decimal number and fill in the
blanks.
(11111111)2 = (_________________________)16
(100000000)2 = (_________________________)16
(1010101011)2 = (_________________________)16
(110110101011)2 = (_________________________)16
(100000000101)2 = (_________________________)16
(1101101101101100)2 = (_________________________)16
(101111100011)2 = (_________________________)16
30 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

(1110000010111011)2 = (_________________________)16
(110000011101101)2 = (_________________________)16
(10000110101010111)2 = (_________________________)16
(10101011111)2 = (_________________________)16
(11000000111111)2 = (_________________________)16
(101010101)2 = (_________________________)16
(1111111111111111)2 = (_________________________)16
(1111000011110000)2 = (_________________________)16
(110011001100110011)2 = (_________________________)16
Note: To solve above examples recommended to use method2

Practice: Match the binary number to its equivalent hexa decimal number.
Binary Hexa-Decimal
10101100110 786
11110000110 665
10001110110 566
11001100101 5C6
10111000110 476

Hexa-Decimal to Binary conversion:


 Any hexa decimal number can be converted into the binary number in two way
1. Using two level conversion (Indirect method)
In this approach convert the hexa decimal number into the decimal number, and again convert
the resultant decimal number into the binary.
Example: (4025)16 = ( ? )2
(4025)16 = ( ? )10 = ( ? )2
2. Hexa decimal to binary (Direct method)
In this way replace the each hex digits by the 4 digit binary number.

Example1: (4025)16 = ( ? )2
Sol: 4 0 2 5
Replace all the hex digits by the binary number, write the binary in four bit representation for
each hex digits separately.
In four bits binary number of hex digit 4 is 0100, binary number of hex digit 0 is 0000, binary
number of hex digit 2 is 0010, binary number of hex digit 5 is 0101
4 0 2 5
0100 0000 0010 0101
(4025)16 = (0100000000100101)2

Example2: (6AF5)16 = ( ? )2
Sol: Replace each digit by four bit binary number
6 by 0110, A by 1010, F by 1111, 5 by 0101
6 A F 5
0110 1010 1111 0101
(6AF5)16 = (11010101111 0101)2
Note: Write the binary number after removing extra beginning 0.

Example3: (FACE)16 = ( ? )2
31 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

Sol: Replace each digit by four bit binary number


F A C E
15 10 12 14
1111 1010 1100 1110
(FACE)16 = (1111101011001110)2
Example5: (CAT)16 = ( ? )2
Sol: The number CAT is an invalid hexa decimal number because digits T is not allowed in
hexa decimal representation an allowed digits are between 0 to 9, A to F, a to f only.

Practice: Convert the given hexa decimal numbers into the equivalent binary and fill in the blanks
(424)16 = (_______________________________________)2
(6445)16 = (_______________________________________)2
(52A5)16 = (_______________________________________)2
(B53F)16 = (_______________________________________)2
(A10BC)16 = (_______________________________________)2
(5743)16 = (_______________________________________)2
(8914)16 = (_______________________________________)2
(35EE)16 = (_______________________________________)2
(F2C5)16 = (_______________________________________)2
(346)16 = (_______________________________________)2
(AB3356)16 = (_______________________________________)2
(3785)16 = (_______________________________________)2
(CD793)16 = (_______________________________________)2
(30)16 = (_______________________________________)2
(50C)16 = (_______________________________________)2
(63467)16 = (_______________________________________)2

Practice: Match the hexa decimal number to its equivalent binary number.
Hexa Binary
3145 110001101001011
5EF3 110001111110010
634B 11000101000101
7486 101111011110011
63F2 111010010000110
Octal to Hexa-Decimal
 As we know base of octal number is 8, and the base of hexa decimal number is 16
 We can convert the any octal number into the hexa decimal number by using two methods.
a. Method1 (octal to decimal, Decimal to Hexa-decimal)
(octal)8 = (decimal)10 = (hexa)16
b. Method2 (octal to binary, binary to Hexa-decimal)
(octal)8 = (binary)2 = (hexa)16
Note: Octal to hexa-decimal conversion directly is not possible. Because there are no direct methods
available for octal to hexa-decimal conversion.

Binary to hexa-decimal conversion using method1:


 In this method two level conversion is required, first we should convert the octal into decimal
number, and then resultant decimal number should be converted into hexa-decimal.
Step1: Octal to Decimal
32 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

Step2: Decimal to Hexa-decimal

Example1: (237)8 = ( ? )16


Step1: Octal to decimal
(237)2 = ( ? )10
2+3+7
2*82 + 3*81 + 7*80
2*64 + 3*8 + 7*1
128 + 24 + 7 = (159)10
Step2: Decimal to hexa-decimal
(159)10 = ( ? )16

Final result is:


(237)8 = ( 9 F )16

Note: This method is too lengthy process of binary to hexa-decimal conversion, therefore
recommended to use method2.

Octal to hexa decimal conversion using Method2:


 In this method first we need to convert the octal number into the binary and then convert the
binary into hex.
 This method very fast because calculations are not required. Because octal to binary and binary to
hexa decimal conversion is very easy.

Example1: (237)8 = ( ? )16


Step1: Convert the octal number into the binary, convert each octal digit in three bit binary number.
Octal: 2 3 7
Binary: 010 011 111
(237)8 = (10011111)2
Step2: Convert the binary into hexa decimal by making four digits group of binary and replace the
each four digits group by the equivalent hexa decimal digit
(10011111)2 = ( ? )16
Binary: 1001 1111
Hexa : 9 F
Final result is (237)8 = (10011111)2 = ( 9F )16

Example2: (3572)8 = ( ? )16


Step1: Convert the the octal number into the binary, convert each octal digit in three bit binary
number.
Octal: 3 5 7 2
Binary: 011 101 111 010
(3572)8 = (11101111010)2
Step2: Convert the binary into hexa decimal by making four digits group of binary and replace the
each four digits group by the equivalent hexa decimal digit
(11101111010)2 = ( ? )16
Binary: 111 0111 1010
33 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

Hexa : 7 7 A
Final result is (3572)8 = (11101111010)2 = ( 77A )16

Example3: (287)8 = ( ? )16


Solve: 287 is an invalid octal number so the conversion is not possible.

Practice: Convert the given octal numbers into the equivalent hexa-decimal number and fill in the
blanks.
(575)8 = (___________)16
(3765)8 = (___________)16
(287)8 = (___________)16
(33553)8 = (___________)16
(5276)8 = (___________)16
(6246)8 = (___________)16
(12345)8 = (___________)16
(634)8 = (___________)16
(25)8 = (___________)16
(10)8 = (___________)16

Note: To solve above examples recommended to use method2

Practice: Match the Octal number to its equivalent hexa decimal number.
Octal Hexa-Decimal
2546 786
3606 665
2166 566
3145 5C6
2706 476
Hexa-Decimal to octal
 As we know base of octal number is 8, and the base of hexa decimal number is 16
 We can convert the any hexa decimal number into the octal number by using two methods.
c. Method1 (hex to decimal, Decimal to octal)
(hexa)16 = (decimal)10 = (octal)8
d. Method2 (Hex to binary, binary to octal)
(hexa)16 = (binary)2 = (octal)8
Note: Hexa to octal direct conversion method is not available therefore hexa to octal direct conversion
is not possible.

Hexa-decimal to octal conversion using method1:


 In this method two level conversion is required, first we need to convert the hex number into the
decimal number, and then resultant decimal number should be converted into an octal number.
Step1: Hexa-decimal to Decimal
Step2: Decimal to Octal

Example1: (2F7)16 = (?)8


Step1: Hexa decimal to decimal
( 2F7 )16 = ( ? )10
2+F+7
34 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

2*162 + F*161 + 7*160


2*256 + 15*16 + 7*1
512 + 240 + 7 = (759)10

Step2: Decimal to hexa-decimal


(759)10 = ( ? )8

Final result is:


(2F7)16 = (759)10 = (1367)8

Note: This method is too lengthy process of binary to hexa-decimal conversion, therefore
recommended to use method2.

Hexa decimal to octal conversion using Method2:


 In this method first we need to convert the hexa decimal number into the binary and then convert
the binary into octal.
 This method very fast because calculations are not required. Because Hex to binary and binary to
octal conversion is very easy.

Example1: (2F7)16 = (?)8


Step1: Convert the hex number into the binary, convert each hex digit in four bit binary number.
Hex: 2 F 7
Binary: 0010 1111 0111
(2F7)16 = (1011110111)2
Step2: Convert the binary into octal number by making three digits group of binary and replace the
each three digits group by the equivalent octal digit
(2F7)16 = (1011110111)2
Binary : 001 011 110 111
Octal : 1 3 6 7
Final result is (2F7)16 = (1011110111)2 = (1367)8

Example2: (52DE9)16 = (?)8


Step1: Convert the hex number into the binary, convert each hex digit in four bit binary number.
Hex: 5 2 D E 9
Binary: 0101 0010 1101 1110 1001
(52DE9)16 = (1010010110111101001)2
Step2: Convert the binary into octal number by making three digits group of binary and replace the
each three digits group by the equivalent octal digit
(52DE9)16 = (1010010110111101001)2
Binary : 1 010 010 110 111 101 001
Octal : 1 2 2 6 7 5 1
Final result is (52DE9)16 = (1010010110111101001)2 = (1226751)8

Example3: (2F9H)16 = (?)8


35 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

Sol: 2F9H is an invalid octal number.

Practice: Convert the given hexa decimal numbers into the equivalent octal number and fill in the
blanks.
(CABE)16 = (___________)8
(2524)16 = (___________)8
(93A)16 = (___________)8
(A1F9)16 = (___________)8
(7634)16 = (___________)8
(DEF0)16 = (___________)8
(63EE5)16 = (___________)8
(5246)16 = (___________)8
(FADE5)16 = (___________)8
(968D)16 = (___________)8

Practice: Match the hex number to its equivalent octal number.


Hexa-Decimal Octal
786 2546
665 175351
566 2166
5C6 3145
476 2706
FAE9 3606

Decimal to Any base conversion:


(number)10 = ( ? )r
In this type of conversion given decimal number will be divided by the base of the conversion
number. According to the required conversion based of the required number is r therefore divide the
decimal number by r till the outcome quotient is more than of 10. And collect all the reminder comes
after the each division operations in reverse order (bottom to top order).
In this conversion r is the base of required number in which form you want to convert the decimal
number.
If r is 2 then allowed digits are 01 only
If r is 3 then allowed digits are 012 only
If r is 4 then allowed digits are 0123 only
If r is 5 then allowed digits are 01234 only…etc

For more clarity consider the given example:


Example: (250)10 = (?)r
Step1: Divide the decimal number 250 by the required base r and collect the quotient and reminder
separately.

r ) 250 ( ?

Example1: Convert the given decimal number in the base 2, base3, base 4, base 5.
(28)10 = (?)2 = (?)3 = (?)4 = (?)5
Sol: (28)10 = ( ? )2 In this case r is 2
(28)10 = ( ? )3 In this case r is 3
36 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

(28)10 = ( ? )4 In this case r is 4


(28)10 = ( ? )5 In this case r is 5

Practice: Fill the equivalent binary number in the blanks


(10)10 = (_______________)2 = ( ____________)3 = ( ____________)4 = ( ____________)5
(7)10 = (_______________)2 = ( ____________)5 = ( ____________)7 = ( ____________)9
(15)10 = (_______________)4 = ( ____________)6 = ( ____________)8 = ( ____________)11
(27)10 = (_______________)2 = ( ____________)3 = ( ____________)7 = ( ____________)12
(65)10 = (_______________)3 = ( ____________)4 = ( ____________)5 = ( ____________)13
(63)10 = (_______________)4 = ( ____________)3 = ( ____________)5 = ( ____________)14
(64)10 = (_______________)5 = ( ____________)5 = ( ____________)7 = ( ____________)15
(127)10 = (_______________)6 = ( ____________)5 = ( ____________)8 = ( ____________)16
(255)10 = (_______________)7 = ( ____________)8 = ( ____________)9 = ( ____________)12
(260)10 = (_______________)8 = ( ____________)4 = ( ____________)11 = ( ____________)14
(1)10 = (_______________)9 = ( ____________)2 = ( ____________)12 = ( ____________)15
(2)10 = (_______________)10 = ( ____________)9 = ( ____________)6 = ( ____________)16
(4)10 = (_______________)2 = ( ____________)3 = ( ____________)4 = ( ____________)5
(8)10 = (_______________)3 = ( ____________)4 = ( ____________)5 = ( ____________)6
(16)10 = (_______________)4 = ( ____________)5 = ( ____________)6 = ( ____________)7
(32)10 = (_______________)5 = ( ____________)6 = ( ____________)7 = ( ____________)8
(64)10 = (_______________)6 = ( ____________)7 = ( ____________)8 = ( ____________)9
(128)10 = (_______________)3 = ( ____________)5 = ( ____________)7 = ( ____________)8
(256)10 = (_______________)2 = ( ____________)3 = ( ____________)4 = ( ____________)5
(512)10 = (_______________)5 = ( ____________)6 = ( ____________)7 = ( ____________)8
(1024)10 = (_______________)3 = ( ____________)5 = ( ____________)6 = ( ____________)8
(275)10 = (_______________)2 = ( ____________)8 = ( ____________)10 = ( ____________)16
(369)10 = (_______________)2 = ( ____________)8 = ( ____________)10 = ( ____________)16

Note: Before solving these practice questions you should practice the previous solved example1

Any base to Decimal conversion:


(number)r = ( ? )10
 In this type of conversion we need to multiply all the digits of given number by the increasing
power of r from right to left order and calculate the summation of all the outcomes.
Ex: (Dn…... D4 D3 D2 D1)r = ( ? )10
Sol: Dn*rn-1…D4*r3 + D3*r2 + D2*r1 + D1*r0
In this summation series replace all occurrences of the r by the base of given number which you
want to convert into the decimal number.
37 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

Example1: (231)5 = ( ? )10


-Note: Make sure allowed digits in base 5 are 01234 only.

Sol: 2*52 + 3*51 + 1*50


2*25 + 15 + 1
50 + 15 + 1
66
Result is (231)5 = ( 66 )10
Any to Any base conversion
 In this type of conversion we can convert any given base to required base.
 There is no direct method available for any to any conversion
Consider the given example
( x )m = ( ? ) n
If the base of given number is „m‟ and the base of required number is „n‟ then first we need to
perform base „m‟ to base 10 (decimal) conversion and the resultant base 10 number again need to
convert base 10 (decimal) to base „n‟ conversion.
Step1: ( x )m = ( ? )10
Step2: ( result )10 = ( ? )n
Example1: (213)5 = ( ? )3
Note: Allowed digits in base 5 are 01234 and allowed digits in base 3 are 0 1 2
Sol:
Step1: (213)5 = ( ? )10
2*52 + 1*51 +3*50
2*25 + 1*5 + 3*1
50 + 5 + 3 = 58
(213)5 = (58)10
Step2: (58)10 = (?)3

(213)5 = (58)10 = (2011)3


(213)5 = (2011)3

Example2: (2534)6 = ( ? )4
Sol:
Step1: (2534)6 = ( ? )10
2*63 + 5 *62 + 3*61 + 4*60
2*216 + 5*36 + 3*6 + 4*1
432 +180 + 18 + 4
(2534)6 = (634)10
Step2: (634)10 = (?)4
38 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

(2534)6 = (634)10 = (21322)4


(2534)6 = (21322)4
Example3: (275)5 = ( ? )3
Sol: 275 is an invalid number for the base 5 representation because in base 5 allowed digits are
01234 only, but in 275 the digits 7 and 5 is an invalid digits for the base5

Practice: Convert the given hexa decimal numbers into the equivalent octal number and fill in the
blanks.
(12102)3 = (___________)2 = (___________)4 = (___________)5
(2431)5 = (___________)2 = (___________)3 = (___________)4
(6352)7 = (___________)6 = (___________)5 = (___________)4
(42321)6 = (___________)2 = (___________)4 = (___________)5
First 16 decimal, binary, octal, hexa decimal number table
Decimal Binary Octal Hexa-decimal
0 0000 0 0
1 0001 1 1
2 0010 2 2
3 0011 3 3
4 0100 4 4
5 0101 5 5
6 0110 6 6
7 0111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F

Direct binary to decimal conversion with the help of 2^n series

 We can convert any binary number into the decimal value using this table by replacing the all
occurrences of the binary bit 1 by the corresponding decimal value positionally according to the
given series and calculate the sum
39 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

 If position of any occurrence of 1 in the binary bit is 16 then replace the binary bit 1 by the
32768(215)
 If position of any occurrence of 1 in the binary bit is 9 then replace the binary bit 1 by the 256(215)
 If position of any occurrence of 1 in the binary bit is 5 then replace the binary bit 1 by the
16(25)…etc. Apply this procedure for all occurrences of the 1 in the binary number
Ex1: (11111)2 = (?)10
Sol: 1 1 1 1 1
16 + 8 + 4 + 2 + 1 = 31
(11111)2 = (31)10
Ex2: (11110)2 = (?)10
Sol: 1 1 1 1 0
16 + 8 + 4 + 2 + 0 = 30
(11110)2 = (30)10
Ex3: (11100)2 = (?)10
Sol: 1 1 1 0 0
16 + 8 + 4 + 0 + 0 = 28
(11100)2 = (28)10
Ex4: (11000)2 = (?)10
Sol: 1 1 0 0 0
16 + 8 + 0 + 0 + 0 = 24
(11000)2 = (24)10
Ex5: (10000)2 = (?)10
Sol: 1 0 0 0 0
16 + 0 + 0 + 0 + 0 = 16
(10000)2 = (16)10
Ex6: (10100)2 = (?)10
Sol: 1 0 1 0 0
16 + 0 + 4 + 0 + 0 = 20
(10100)2 = (20)10
Ex7: (10110)2 = (?)10
Sol: 1 + 0 + 1 + 1 + 0
16 + 0 + 4 + 2 + 0 = 22
(10110)2 = (22)10
Ex8: (10101010)2 = (?)10
Sol:

(10101010)2 = (170)10
Practice1: Convert the given binary numbers into the decimal and fill in the blanks
(1)2 = (________ )10
(10)2 = (________)10
(100)2 = (________)10
(1000)2 = (________)10
(10000)2 = (________)10
40 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

(100000)2 = (________)10
(1000000)2 = (________ )10
(10000000)2 = (________)10
(11)2 = (________)10
(111)2 = (________)10
(1111)2 = (________)10
(11111)2 = (________)10
(111111)2 = (________ )10
(1111111)2 = (________)10
(11111111)2 = (________)10

Practice2: Convert the given binary numbers into the decimal and fill in the blanks
(1010)2 = (________)10
(1101)2 = (________)10
(1111)2 = (________)10
(101101)2 = (________)10
(10000)2 = (________)10
(11111)2 = (________)10
(1000000)2 = (________)10
(111111)2 = (________)10
(10000000)2 = (________)10
(1111111)2 = (________)10
(11111111)2 = (________)10
(100000000)2 = (________)10
(10101011)2 = (________)10
(1000000000000000)2 = (________ )10
(111111111111111)2 = (________)10
(1111111111111111)2 = (________)10

Direct decimal to binary conversion with the help of 2^n series

 By using this table we can convert any decimal number into binary number without division
method using the given steps.
Ex1: (5)10 + ( ? )2
Sol: 5 can be written as 4+1

(5)10 + ( 101 )2
41 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

Ex: (150)10 = ( ? )2
Sol: 150 can be written 128+16+4+2
Put 1 for 128, 0 for 64, 0 for 32, 1 for 16, 0 for 8, 1 for 4, 1 for 2, 0 for 1.
So the binary is 10010110

Binary Addition:
Rule: 0+0 = 0
0+1 = 1
1+0 = 1
1+1 = 10
Addition of 1+1 is 2 but in binary number 2 is not allowed so in place of 2 we need to write the binary
of 2 as 10. In 10, 1 is the carry bit, and 0 is the addition
Ex: Perform the binary addition of given numbers
00001010
01010001
--------------------
01011011
Ex: Perform the binary addition of given numbers
(10) 0 0 0 0 1 0 1 0
(5) 0 0 0 0 0 1 0 1
--------------------
(15) 0 0 0 0 1 1 1 1

Ex: Perform the binary addition of given numbers


00001010
00001100
Sol:
42 | P a g e C L a n g u a g e M a t e r i a l b y G i r r a j S h a r m a

Ex: Perform the binary addition


10101010
11111111
Sol:

You might also like