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

PPSC - I

The document outlines the process of programming in C, including creating, compiling, linking, and executing programs. It also covers number systems, conversions among bases, and techniques for converting between decimal, binary, octal, and hexadecimal formats. Additionally, it discusses storing integers and real numbers in programming.

Uploaded by

kvs venkat
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
4 views89 pages

PPSC - I

The document outlines the process of programming in C, including creating, compiling, linking, and executing programs. It also covers number systems, conversions among bases, and techniques for converting between decimal, binary, octal, and hexadecimal formats. Additionally, it discusses storing integers and real numbers in programming.

Uploaded by

kvs venkat
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 89

PROGRAMMING

FOR PROBLEM
SOLVING USING C
Creating &
Running the
Program
•Writing(Creating)
/Editing:
• The first step in creating programs is, Creating ,writing or editing
the program. A program can be written in any text editor like
notepad. After writing a program, the program must be saved,
In C language, the program is saved with the extension “.c”.
This is the source program written in a high-level language.
Compilation
:
After writing and saving the source program, the next step is
compilation. Here we will use a software called as compiler,
which converts a program written in high-level language into
machine language. The resultant file is known as an object file
in C. The extension of that file is “.obj”.
Linking:
After compilation the next step is linking. Here software called linker is
used. The linker links the program with external library files which
contains the code for predefined functions and creates an executable
file. The extension of the executable file is “.exe”.
Execution :

Finally after the executable file is created after linking, the next
step is execution. The operating system executes the
executable file which is the machine code with the help of the
CPU and other hardware components
Computer
Numbering
System
COMMON NUMBER SYSTEMS
QUANTITIES/COUNTING (1 OF
3)
Hexa-
Decimal Binary Octal decimal
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
p. 33
QUANTITIES/COUNTING (2 OF
3)
Hexa-
Decimal Binary Octal decimal
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
QUANTITIES/COUNTING (3 OF
3)
Hexa-
Decimal Binary Octal decimal
16 10000 20 10
17 10001 21 11
18 10010 22 12
19 10011 23 13
20 10100 24 14
21 10101 25 15
22 10110 26 16
23 10111 27 17 Etc.
CONVERSION AMONG BASES

• The possibilities:
Decimal Octal

Binary Hexadecimal

pp. 40-
46
QUICK EXAMPLE

2510 = 110012 = 318


= 1916
Base
DECIMAL TO DECIMAL (JUST
FOR FUN)

Decimal Octal

Binary Hexadecimal

Next slide…
Weight

12510 => 5 x 100 = 5


2 x 101 = 20
1 x 102 = 100
125

Base
BINARY TO DECIMAL

Decimal Octal

Binary Hexadecimal
BINARY TO DECIMAL

• Technique

• Multiply each bit by 2n, where n is the “weight” of the bit

• The weight is the position of the bit, starting from 0 on the


right
• Add the results
EXAMPLE
Bit “0”

1010112 => 1 x 20 = 1
1 x 21 =
2
0 x 22 =
0
1 x 23 =
8
0 x 24 =
0
1 x 25 =
32

4310
OCTAL TO DECIMAL

Decimal Octal

Binary Hexadecimal
OCTAL TO DECIMAL

• Technique

• Multiply each bit by 8n, where n is the “weight” of the bit

• The weight is the position of the bit, starting from 0 on the


right
• Add the results
EXAMPLE

7248 => 4 x 80 = 4
2 x 81 = 16
7 x 82 = 448
46810
HEXADECIMAL TO DECIMAL

Decimal Octal

Binary Hexadecimal
HEXADECIMAL TO DECIMAL

• Technique

• Multiply each bit by 16n, where n is the “weight” of the bit

• The weight is the position of the bit, starting from 0 on the


right
• Add the results
EXAMPLE

ABC16 => C x 160 = 12 x 1 = 12


B x 161 = 11 x 16 = 176
A x 162 = 10 x 256 = 2560
274810
DECIMAL TO BINARY

Decimal Octal

Binary Hexadecimal
DECIMAL TO BINARY

• Technique
• Divide by two, keep track of the remainder
• First remainder is bit 0 (LSB, least-significant bit)
• Second remainder is bit 1
• Etc.
EXAMPLE
12510 = ?2 2 125
2 62 1

2 31 0
15 1
2
7 1
2
2 3 1

2 1 1
0 1

12510 = 11111012
OCTAL TO BINARY

Decimal Octal

Binary Hexadecimal
OCTAL TO BINARY

• Technique
• Convert each octal digit to a 3-bit equivalent binary
representation
EXAMPLE
7058 = ?2

7 0 5

111 000 101

7058 = 1110001012
HEXADECIMAL TO BINARY

Decimal Octal

Binary Hexadecimal
HEXADECIMAL TO BINARY

• Technique
• Convert each hexadecimal digit to a 4-bit equivalent binary
representation
EXAMPLE
10AF16 = ?2

1 0 A F

0001 0000 1010 1111

10AF16 = 00010000101011112
DECIMAL TO OCTAL

Decimal Octal

Binary Hexadecimal
DECIMAL TO OCTAL

• Technique
• Divide by 8
• Keep track of the remainder
EXAMPLE
123410 = ?8

8 1234
154 2
8
19 2
8
2 3
8
0 2

123410 = 23228
DECIMAL TO HEXADECIMAL

Decimal Octal

Binary Hexadecimal
DECIMAL TO HEXADECIMAL

• Technique
• Divide by 16
• Keep track of the remainder
EXAMPLE
123410 = ?16

16 1234
16 77 2

16 4 13 = D
0 4

123410 = 4D216
FRACTIONS
.14579
• Decimal to binary x 2
3.14579 0.29158
x 2
0.58316
x 2
1.16632
x 2
0.33264
x 2
0.66528
x 2
1.33056
11.001001... etc.

p. 50
EXERCISE – CONVERT ...
Hexa-
Decimal Binary Octal decimal
29.8
101.1101
3.07
C.82
EXERCISE – CONVERT …
Hexa-
Decimal Binary Octal decimal
29.8 11101.110011… 35.63… 1D.CC…
5.8125 101.1101 5.64 5.D
3.109375 11.000111 3.07 3.1C
12.5078125 1100.10000010 14.404 C.82
Storing
Integers
No Fractional Part
Sign
Unsigned
Storing
Real
Numbers
Floating Point Representation

You might also like