86%(242)86% found this document useful (242 votes) 741K views530 pagesPython Class 11 Full Book Sumita Arora Good Quality Print
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
18
‘
Z
we
49-78
COMPUTER SYSTEM Overview
1.1 Introduction
1.2. Basic Computer Organization
12.1
122
123
124
125
126
Input Unit 2
Output Unit 3
The CPU (Central Processing Unit) 3
The Memory [Main Memory/Primary Memory] 4
Storage Unit 6
The System Bus 7
1.3 Mobile System Organization
14 Types of Software
Ltd
142
143
System Softoare 10)
Application Software 11
Software Libraries. 13
DATA REPRESENTATION
241 Introduction
22. Digital Number Systems
224
222
223
224
Decimal Number System 20
Binary Nuamber System 20
Octal Number System 21
Hexadecimal Number System 22
2.3. Number Conversions
231
232
233
234
235
23.6
237
238
23.9
23.10
Decimualto-Binary Conversion 23
Binary-to-Decimal Conversion 26
Decinal-to-Octal Conversion 27
Octal-to-Decimal Conversion 2:
Octal-to-Binary Conversion 27
Binary-to-Octal Conversion 2
Decimal-to-Hex Conversion 28
Hex-to-Decimal Conversion 29
Binary-to-Hex Conversion 29
Her-to-Binary Conversion 29
24. Representing Unsigned Integers in Binary
25 Binary Addition
2.6 Character/S
261
262
263
Representation
ASCII Code 35
ISCH Code 36
Unicode 37
BOOLEAN LOGIC
3.1 Development of Boolean Logic
3.2. Binary Valued Quantities
ao: 2
BY ER NIKHIL SIR
Contents
10
19
20
23
31
32,
a4
49
50BY ER NIKHIL SIR
3.3 Logical Operations ey
33.1 Logical Function or Compound Statement 50
33.2 Logical Operators 51
33.3 Evaluation of Boolean Expressions using Truth Table 53
34 BasicLogic Gates si
34.1 Inverter (NOT Gate) 57
342 OR Gate 57
343° AND gate 58
3.5. BasicPostulates of Boolean Logic 59
36 Principle of Du: Es
37 Basie Theorems of Boolean Algebra/Logic 6
37.1 Propertis of O and 1. 60
3.72. Indempotence Law 61
3.7.3. Involution 61
3.74 Complementarity Law 61
3.75 Commutative Law 62
3.7.6 Associative Law 62
3.7.7 Distributive Law 63
3.78 Absorption Law 64
3.79 Some Other Rules of Boolean Logic Algebra 63
3.8. DeMorgan’s Theorems 65
38.1 DeMorgan’s First Theorem 65
3.8.2 DeMorgan’s Second Theorem 66
3.9. Moreabout Logic Gates 68
391 NOR Gate 68
3.92 NANDGate 68
3.9.3 XOR Gate (Exclusive OR Gate) 69
394 XNOR Gate (Exclusive NOR gate) 70
4 — Insight into PRocraM EXECUTION
79-94
4.1 Introduction 9
42. Basic Flow of Compilation 80
43. Understanding Translation Process 80
43.1 The Compilation Process 80
43.2 The Interpretation Process. 83
44 Role ofan Operating System in Running a Program a
45: Introduction to Parallel Computing 90
4.6 Cloud Computing a
COMPUTATIONAL THINKING AND GETTING STARTED WITH PYTHON
5.1 Introduction 5
5.2 Computational Thinking sd
5.3 Python - Pluses 99
54 Python ~ Some Minuses (So Human Like) 100
5.5 Working in Python 101
55.1 Working in Default CPython Distribution 101
55.2 Working in Anaconda Distribution 105
553 Writing and Compiling Python Program with Command Line in Linux 111
5.6 Understanding First Program/Script uz
| re6 PYTHON FUNDAMENTALS
11 158 ol
62
63
64
65
66
Introduction
Python Character Set
Tokens
63.1 Keywords 121
63.2 Lentfers (Names) 121
633° Literals (Values 121
634 Operators 129
635 Punctuators 130
Barebones of a Python Program
Variables and Assignments
65.1 Creating a Variable 13
652 Multiple Assignments 138
653. Variable Definition 140
654 Dynamic Typing 141
Simple Input and Output
66.1 Reading Numbers 143
662 Output Through print) Statement 146
BA DATA HANDLING
1597 212 | 71
| 72
73
74
78
76
Introduction
Data Types
7.21 Numbers 160
722 Strings 163
7.23 Lists and Tuples 165
724 Dictionary 166
Mutable and Immutable Types
73:1 Variable Internals 170
Operators
741 Arithmetic Operators
74.2 Relational Operators 176
743. Identity Operators. 173
74.4 Logical Operators 182
745° Bitwise Operators 186
74.6 Operator Precedence 188
Expressions
7.51 Evaluating Expressions 192
75.2 Type Casting 196
Working with Some Standard Library Modulus
7.61 Working with math Modul of Python 198
7.6.2 Using random Module 200
7.63 Using the statistics Module 202
\8- CONDITIONAL AND ITERATIVE STATEMENTS
213 270 8.1 Introduction
8.2. Types of Statements in Python
8.3 Statement Flow Control
= |
BY ER NIKHIL SIR
119
120
120
131
135
142
159
160
167
172
191
198
213
24
21584. Program Logic Development Tools
841 Flowcharts 217
85. Theif Statements of Python
851 TheifStotement 218
852 The if-else Statement 220
853. The if-elifStalement
854 The nested if Statement 227
86. Repetition of Tasks ANecessity
87 Therange() Function
88. Iteration/Looping Statements
881 The for Loop 236
882 The while Loop 239
$883 Loop else Statement. 243
8.84 Jump Statements ~break and continue 244
885 Loop ele Slatement 248
8.86 Nested Loops 25
9 STRING MANIPULATION
271 - 294 9.1. Introduction
92. Traversinga String
9.3 String Operators
934 Basie Operators 273
932 Membership Operators 276
| 933 Comparison Operators 277
9.4. String Slices
95. String Functions and Methods
10 | DesuccinG Procrams
295 - 310 10.1 Introduction
10.2 Whatis Debugging?
103. Errorsand Exceptions
103.1 Errors in a Program 296
1032. Exceptions 297
10.4 Howto Debuga program?
10441 Debugging Techniques 299
10.5 Using Debugger Tool
105.1 Working with Integrated Debugger Tool of Spyder IDE. 302
1052 Working with Python Debugger — pdb 306
TL UIST MANIPULATION
311-342 11.1 Introduction
11.2 Creating and Accessing Lists
M21 Creating Lists 312
11.22 Accessing Lists 314
11.3. List Operations
113.1 Joining Lists 319
xii
BY ER NIKHIL SIR
217
218
232
234
236
an
2
273
278
281
295
296
296
299
302
ait
312
31912
343 - 362
13
363 - 386
14
387 - 402
15
403 - 420
1132 Repeating or Replicating Lists 320
1133 Sicing the Lists 320
11.4 Working with Lists
11.5 List Functions and Methods
TUPLES.
12.1 Introduction
12.2 Creating and Accessing Tuples
12.2.1 Creating Tuples 344
1222 Accessing Tuples 345
12.3. Tuple Operations
123.1 Joining Tuples 348
12.32 Slicing the Tuples 319
124 Tuple Functions and Methods
DICTIONARIES
Ba
Introduction
132 Dictionary -Key:Value Pairs
13.2.1 Creating a Dictionary 364
13.2.2. Accessing Elements of a Dictionary 365
13.2.3. Characteristics of a Dictionary 368
13.3. Working with Dictionaries
13.3.1 Multiple Ways of Creating Dictionaries 369
13.32. Adding Elements to Dictionary 371
13.33. Updating Existing Elements in a Dictionary 372,
13.34 Deleting Elements from a Dictionary 373
1335 Checking for Existence of a Key 374
1336 Pretty Printing a Dictionary 375,
133.7 Counting Frequency of Elements in a List using Diction
376
134 Dictionary Functions and Methods
UNDERSTANDING SORTING
44
Introduction
142. What isSorting?
143
144
BubbleSort
Insertion Sort
RELATIONAL DATABASES
151
152
153
154
155
15.6
157
Introduction
Purpose of DBMS
Relational Database Model
‘The Relational Model Terminology
154.1 Views 409
154.2. Structure of Relational Databases 409
Brief History of MySQL.
MySQL Database System
Starting MySQL
BY ER NIKHIL SIR
323
325
343
343
348
353
363
363
369
377
387
388
388
393
403
404
404
407
411
412
413} 15.8 MySQLand SQL
1581 Processing Capabilities of SQL 414
1582. Data Definition Language 415
15.8.3 Classification of SOL Statements 416
16 SIMPLE QUERIES IN SQL
421 — 460 16. Introduction
16.2. Some MySQL SQL Elements
16.2.1. Literals 422
16.22 Data Types 422
1623 Null Values 425
16.24 Comments 4:
163. SQLCommand Syntax
164 Sample Database
165. Making Simple Queries
165.1 Accessing Database 429
1652. The SELECT Command 429
1653. Selecting All Colunns 430
1654 Reordering Columns in Query Results 430
1655 Eliminating Redundant Data (with keyword DISTINCT) 430
165.6 Selecting from all the Rows ~ ALL Keyword 431
165.7, Viewing Structure of Teble 431
1658 How to Perform Simple Calculations ? 432
165.9. Scalar Expressions with Selected Fields 433
165.10 Using Column Aliases 433
165.11 Handling Nulls 434
165.12 Putting Text in the Query Output 436
165,13 Selecting Specific Rows - WHERE clause 437
165.14 Relational Operators 437
165.15 Logical Operators 438
16.5.16 Condition Based on a Range 438
165.17 Condition Based on a List 439
165.18 Condition Based on Pattern Matches 440
165.19 Searching for NULL 441
165.20 Operator Precedence 442
165.21 Sorting Results - ORDER BY clause 442
16.6 MySQL Functions
166.1 String Functions 444
1662 Numeric Functions 444
16.6.3 Date and Time Functions 445
167 Aggregate Functions
17 _{) Taste CREATION AND DATA MANIPULATION COMMANDS
461 486| 174 Introduction
17.2 Databases in MySQL
1721 Creating Datibases 462
1722 Opening Databases 462
1723 Removing Datbass 462
a=
BY ER NIKHIL SIR
44
421
422
425
426
428
444
448
461
461BY ER NIKHIL SIR
173. Creating Tables on
173.1 Data Integrity Trough Constraints 463
17.4 Changing Data with DML Commands ae
174.1 Inserting Data into Table 472
174.2 Modifying Data with UPDATE Commend 474
1743. Deleting Data with DELETE Command 475
175. More DDL Commands ve
175.1 ALTER TABLE Command 47
a 175.2. The DROP TABLE Command 479
18 | Basics OF NOSQL DATABASE - MONGODB
487 - 496 18.1 Introduction 487
182. What are NoSQL databases ? 487
18.2.1. Types of NoSQL Databases 488
18.2.2 Advantages and Disadeantages of NoSQL Databases 482
183, Working with MongoDB 493
183.1 MongoDB Terminology 493
183.2. Starting MongoDB Service 494
19 CYBER SAFETY
194.1 Many Ways Websites Track you 498
194.2 Private Browsing and Anonymous Browsing 500
497-510 ‘191. Intreduction 497
19.2 Whatis Cyber Safety? 497
193 Safely Browsing The Wed 498
| 19.4 Identity Protection While Using Internet 498
|
19.5 Confidentiality of Information 500
19.5.1. Practices to Ensure Confidentiality of Information 501
19.6 Cybercrime 503
19.6.1 Reporting Cybercrime 504
19.7 Common Social Networking Sites 505
198 Appropriate Usage of Social Networks 505
19.8.1 What You Should Know ? 505,
19.8.2. What You should do ~ Usage Rules 506
20 ONLINE ACCESS AND COMPUTER SECURITY
| 511-522 20.1 Introduction su
20.2 Threats to Computer Security Sil
20.2.1 Computer Viruses 512
20.2.2 Spyware 512
20,23 Adware 513,
20.2.4 Spamming 513
20.25 PC Intrusion 514
20.26 Eavesdropping 514
20.2.7 Phishing and Pharming 514
20.2.8 Cookies 515203 Solutionsto Computer Security Threats
203.1 Solutions to Viruses, Adware and Spyware 516
203.2 Solutions to Spars, Eavesdropping 517
203.3. Solutions to PC Intrusion
2034. Solutions to Phishing and Pharming Attack 518
204 Firewall - An Important Solution for Computer Security
APPENDICES
523 - 528 Appendix: Installing Python
Appendix B: Arguments to print Function
Appendix C: Formatted Output using String format( }
ADDITIONAL RESOURCE 1
Computer Organization 2
4g ey Truth Table Formation 53
ft complation Process 2
Interpretation Process 83
CPU Functioning 87
Working in Python 1OLE 103
ADDITIONAL RESOURCE 2 Working in Spyder IDE 110
=e Exponent Form 127
i
barebones of Fthon Progam 13
[EEVPERS| | atest Memory 27
adtuicun cues
Mutabilty/Immutability 168
Selected Solutions for chapter 7.209
ADDITIONAL RESOURCE 3 if Statement 219
Program 8.1 in action 222
Statement 226
range( ) Function 234
for Loop 236 i
while Loop 242 ;
Program 8.14 in action 243,
Nested loop 252
Selected Solutions for chapter 8 264
a=
BY ER NIKHIL SIR
515,
519
523
526
527
List of QR Codes
string Traversal 272
String Sices 279
Selected Solutions for chapter 9269
Working in péb_ 305
Lst storage 315
True copying (Lust) 325
F Selected Solutions for chapter 11.339
Tuples vs Lists 347
Selected Solutions for chapter 12 359
Dictionary creation 364
‘Multiple dictionary creation ways 369
Element addition 371
| Selected Solutions for chapter 13 383
Bubble Sort 389
Calculation of no. of Operations 390
Insertion Sort 394
To calculate no. of Operations in
Insertion Sort 395
Selected Solutions for chapter 14 400BY ER NIKHIL SIR
Computer
System Overview
sais
Introduction
Basic Computer Organization
Mobile System Organization
Types of Software
1.1 INTRODUCTION
‘Computers are the machines that have revolutionised the world around us. The way weused to
live around 25-30 years ago is very different from how we live today. A modem age student |
cannot even imagine life, without email, Internet, print outs, playing music on computers or
smartphones, photos just a click away in the form of smartphones and so on. In short, in every
aspect of life around us, we see computers play a role directly ot indirectly.
Computers deliver so much, diligently and efficiently, all thanks to the wonderful combination
of their hardware and software.
® Hardware. The physical electronic components of a computer are called hardware, ¢..,
keyboard, CPU, monitor, printer ete.
Software. These are the recorded instructions and programs that govern the working of a
computer. Recall that a program: is a set of instructions to carry out a specific task or a
special work goal,
In this chapter, we shall discuss computer's functioning in broad sense by discussing
computer system organization and how various types of software aid in computer's overall
performance.
a3
Ee
(iBY ER NIKHIL Si
2 COMPUTER SCIENCE WITH PYTHON ~ x1
1.2 BASIC COMPUTER ORGANIZATION
Computer organization refers to logical structure of a computer describing how its components
are connected to one another ; how they affect one another's functioning, and contribute to
overall performance of the computer.
Computers, as you must be knowing, follow the IPO’ principle, Input -» Process + Output(a
certain input is processed to generate specific output). So, the computer organization is. also like
this — these are component(s) dedicated to obtain input in different forms, component(s)
dedicated to perform processing part and component(s) to produce output in different forms,
{hus basic computer organization is as shown in Figure 1.1. To see the interconnections and
basic working of computer (Computer Organization), scan this OR Code with SIPO app.
To see =
Computer Organization
in-acton
SEE
aun Control enc
&
Scan
QR Code
ALU) Registers
Figure 1.1 Basic Computer Organization,
Let us talk about these functional components of a computer, [LAC nnn
one by one. A computer runs on electricity
ower.
1.2.1. Input Unit pa
‘The input unit is formed by the input devices attached to the computer, Examples of input
devices and media are : keyboard, mouse, magnetic ink character reader (MICR), optical mark
reader (OMR), optical character reader (OCR), joystick ete.
The input unit is responsible for taking input and converting [oie aa
itinto computer understandable form
(the binary code). Since
@ computer operates on electricity, it can understand only the pape ‘es
language of electricity i. either ON or OFF or high voltage phere cereus
or low voltage. That means a computer can understand two
computer.
stages ON/OFF or High/Low voltage or the binary language
that uses just two symbols: 1 for ON and 0 for OFF.
All the inputs consisted of data (on which the action was
(the action to be taken).
—_
tobe performed) as well as the instruction
On the same lines, the computer input also consists of data and instructions. For example if
the given input to the computer is Add 2 and 3 then data consists of 2and 3nd instruction is
Add. Similarly, if the given input is Print “Hello World” then data consists of “Hello World”
and instruction is Print.BY ER NIKHIL
Chapter 1: COMPUTER SYSTEM OVERVIEW 3
The input unit is comprised of different input devices that take the input in different forms and
pass them in digital form to CPU for processing,
Some common input devices are :
( Keyboard. Keyboard is a typewriter like device which is used to type in the letters,
digits and commands.
(i) Mouse. Mouse is pointing device with either a roller on its base or some laser
mechanism. Mouse controls movement of pointer (also called mouse pointer) on screen.
(ii) Microphone (Mic). We can send sound input to computer through a special input
device called microphone or mic in short. A mic converts the sound received into
computer's format, which is called digitized sound or digital audio.
A mic can work if your computer has a special hardware known as sound card.
1.2.2 Output Unit
|
|
|. The output unit is formed by the output devices attached to
| the computer. The output coming from the CPU isin the form Output Unit converts the
|
|
of electronic binary signals which needs conversion in some output in binary form to
form which can be easily understood by human beings ie, human readable form. j
characters, graphical or audio visual form. This function of
conversion is performed by output units.
Some popular output devices are :
(Monitors. Monitor (or “screen’) is the most common form of output from a computer.
It displays information in a similar way to that shown on a television screen. The
picture on a monitor is made up of thousands of tiny coloured dots called pixels.
(i Printers. Printers are the devices that deliver information by means of printed
characters on paper.
|
(iii) Speakers. Speakers receive the sound in form of electric current from the sound card
and then convert it to sound format audible to user.
1.2.3 The CPU (Central Processing Unit)
‘The CPU or the Central Processing Unit is the main control centre and processing unit. Itis also
called brain of the computer as it guides, directs, controls and governs the performance of a
computer. The CPU has some sub-components that help in carrying out the processing ofa task.
These are :
(@ Arithmetic Logic Unit (ALU) (ii) Control Unit (CU) (iif) Registers
(i) Arithmetic Logic Unit (ALU)
The ALU performs all the four arithmetic (+,-,*,/) and some logical <,>, =, <=,>=,!=)
operations, When two numbers are required to be added, these numbers are sent from memory.
to ALU where addition takes place and the result is put back in the memory. In the same way,
other arithmetic operations are performed (through ALU only).
For logical operations also, the numbers to be compared are sent
from memory to ALU where the comparison takes place and ALU a ee
the result is retumed to the memory. The result of a logical (=-1-/) and togie
operation is either TRUE or FALSE. These operations provide 2Perations.
the capability of decision-making to the computer.BY ER NIKHIL Si
4 ‘COMPUTER SCIENCE WITH PYTHON — xj
(ii) Control Unit (CU)
The CU controls and guides the interpretation, flow and manipulation of all data and
information. The CU sends contol signals until the required operations are done properly by
ALU and memory. Another important function of CU is the program execution i, carrying
out all the instructions stored inthe program. The CU gets program instructions from memory
and executes them one after the other. After getting the instructions from memory in CU, the
instruction is decoded and interpreted i.e,, which operation is
to be performed. Then the asked operation is carried out. GU acts as a supervisor by
After the work of this instruction is completed, control unit are ae guiding
sends signal to memory to send the next instruction in © operation taking place,
sequence to CU,
The control unit even controls the flow of data from inp
tut devices to memory and from memory
to output devices.
(ii) Registers
Registers or processor registers are small units of data holding places. The
temporarily hold some important processing-information during the ti
taking place. CPU may store some part data or some memory address or
processor registers.
CPU uses registers to
ime the processing is
some instruction in its
1.2.4 The Memory [Main Memory/Primary Memory]
The memory of a computer is more like a predefined working place, where it temporarily keeps
information and data to facilitate its performance. Each memory location has a unique memory
address. When the task is performed, it clears its memory and memory space is then available
for the next task to be performed. When the power is switched off, everything stored in the
memory gets erased and cannot be recalled.
The memory of a computer can be thought of as ‘cells’. Each of these cells is further broken
down into smaller parts known as bits (se Fig. 1.2). A bit means a binary digit ie, either Oor
A number of bits together are used to store data instructions by their combination,
vn ae IiRrO rE Mars ad
CellO
The memory of computer Is
‘often called main memory of
Figure 1.2 Memory celts.
Das
‘A group of 8 bits is called 2 byte
and a group of 4 bits is called a]
nibble.
One byte is the smallest unit which can represent a data item
or a character. Other units of memory are KB, MB, GB, TB.
A bit is an elementary unit of the memory. Eight bits together
form a byte.
Every higher memory unit is equal to 2" of its lower unit.BY ER NIKHI
Chopter 1: COMPUTER SYSTEM OVERVIEW 5)
Following Table 1.1 lists various memory units used.
rable 1.1 Units of Computer Memory Measurements
Unit [shore Name | _ Full Name Unit ‘Short Name | Full Name
1 Bit Bit Binary Digit 2" ie, 1024 GB 17B Terra Byte
8 Bits 1 Byte Byte 2° ie,, 1024 TB 1PB Peta Byte
2" ie., 1024 Bytes 1KB Kilo Byte 2" ie, 1024 PB 1EB Exa Byte
2" ie, 1024 KB 1MB Mega Byte 2!° ie, 1024 EB 1ZB Zeta Byte
2! ie, 1024MB_ | _1GB Giga Byte :
Since computer's main memory (primary memory) is temporary, secondary memory space is
needed to store data and information permanently for later use. Some most common secondary
storage media are the hard disk, CD-RWs, pen drive etc. The secondary memory devices are
also known as storage devices.
1.2.44 Paris of Main Memory/Primary Memory
In the random-access memory (RAM), the memory cells can be accessed for information
transfer from any desired random location. That is, the process of locating a word in memory is
the same and requires an equal amount of memory, thus the name “random access”.
‘The main drawback of RAM memory is that it is a volatile memory. That is, when the power
goes off, the contents of RAM get erased.
‘The RAM chips in a computer can be of Hoo basic types :
() Dynamic RAM (DRAM). These are made up of transistors and capacitors. The amount
of time taken to produce data required from memory, from the start of access until the
evailability of data is called memory access time. Today’s DRAM chips have access times
ranging from below 20 to 70 nanoseconds.
(i) Static RAM. These are made up of flip-lops' and offer". "smount of time taken to
faster access times (about 10 nanoseconds) than Froguce data required from
DRAMs. memory, from the start of
Static RAMS are thus used in specialized applications _—_accessuntil the avaiablty of
data, is called Memory Access
while dynamic RAMS are used in the primary storage
rime.
sections of most computers.
Read Only Memory (ROM)
‘As the name implies, a read-only memory (ROM) is a memory unit that performs the read
operation only; it does not have a write capability. This implies that the binary information
stored in a ROM is made permanent during the hardware production of the unit and cannot be
altered by writing different words into it (hence non-volatile). Whereas 2 RAM is a general-
purpose device whose contents can be altered during the computational process, a ROM is
Pevbicted to reading words that are permanently stored within the unit: ROMs are used for
applications in which itis known that the information never needs 0 be altered, for example, a
monitor program controlling a machine. These, however, are slower than RAM.
1, A flip-flop is a binary cell capable of storing one bit of information.BY ER NIKHIL SIR
s COMPUTER SCIENCE WITH PYTHON —
‘There are various types of ROM which are given below :
(PROM (programmable ROM). Also called OTP (One Time Programmable). PROM is
user-programmable memory in which information is burnt using special equipment
called a ROM burner.
G EPROM (erasable programmable ROM). In EPROM, one can program the memory
chip (through various mechanisms e.., UV radiation) and erase it many times <
needed. The UV-EPROM can take up to 20 minutes for erasing EPROM contents,
(i) EEPROM (electrically erasable programmable ROM). In EEPROM, the EPROM ig
erased electrically which is faster. Also, with EEPROM, selective bytes can be erased
unlike UV-EPROM which erases fully.
(jv) Flash EEPROM. It is like EEPROM but is very fast comparatively (the erasure of the
entire contents takes less than a second). Also, it erases fully and not selectively.
(2) Mask ROM. Mask ROM refers to a kind of ROM in which the contents are programmed
by the IC manufacturer. It is not a user-programmable ROM.
1.2.5 The Storage Unit
Computers need to store and retrieve data for processing. Since primary memory has a limited
storage capacity and is not permanent, secondary storage devices are used to store large
amount of data permanently. There are various types of secondary devices available these days.
To specify the storage capacity of storage devices, same
units of memory are used, which are used for measuring
F
Bata
primary memory. That is, we can represent the storage % Hard disks “| Magnet
capacity of storage devices in terms of kilo bytes (KBs), mega Media
bytes (MBs), giga bytes (GBs) and tera bytes (TBs) as we do for + CD ROMs Optical
main memory. + DVDs Media
Let us now talk about some most common storage devices. Penidrive Flash
memory
1. Hard Disks ‘ :
The hard disk memories store information on one or more circular platters (or disks) which are
continually spinning. These rotating disks are coated with a magnetic material and stacked
with space between them. Information is recorded on the surface of rotating disks by magnetic
heads as tiny magnetic spots.
The hard disks of today have storage capacity measured in giga bytes upto tera bytes.
2. Compact Disks (CDs)
‘The compact disks or CDs are optical media. The CDs are relatively cheap and have a storage
capacity of upto 700 Mb. There are tliree main types of CDs :
() CD-ROM (Compact Disk-Read Only Memory). This is used only to store
information and cannot be used to store data. It is mainly used for CD distribution
e.g., encyclopedias, software, games, e-books etc.
(i) CD-R (Compact Disk-Recordable). It is mainly used for CD-R and can be written on
only once and disk can’t be erased.
(ii) CD-RW (Compact Disk-Rewritable). CD-RW is an erasable disk you can write on
multiple times.Chopter 1
COMPUTER SYSTEM OvERvieW
3. DVDs
DVD is an optical storage device that looks the same as a compact disc but is able to hold about
15 times as much information and transfer it to the computer about 20 times as fast as a
CD-ROM. A DVD, also called a Super Density disk (SD), can hold upto 17 gigabytes of data or
four hours of movies on a side. DVDs also come in three varieties.
() DVD-ROM. This is read only DVDs iv.
BY ER NIKH|
once recorded initially, you cannot write on it.
(i) DVD-R (DVD-Recordable). DVD-R similar to CD-R’s allow users to write on the disc once
but read it many times.
(ii), DVD-RW (DVD-Rewritable). Most writable DVD drives are DVD-RW You can erase and
read many times on them.
4, Flash Memory
A flash drive is a small, ultra-portable storage device with a ‘solid state’ memory ie, it has no
moving parts unlike magnetic storage devices, nor does it make use of lasers — unlike optical
drives. Instead, it works in a similar way to RAM. The key difference is that data is retained in
Flash memory even when the power is switched off. They are now fairly inexpensive, costing from
% 250/- upwards. Typical sizes range from 256 Mbytes up to 128 GB and beyond.
oe
ih
( Storage of 1 KB means the
following number of bytes :
(@) 1000 (b) 964
(©) 1024 (@) 1086
(ii) One Megabyte is equivalent to
(a) 210 bytes (b) 220 bytes
(€) 230 bytes (d) none of the above
What are the functional components of
2 digital computer ?
What are the components of CPU ?
What is its role ? What is the function
‘of control unit of CPU?
What role does the input unit play in a
computer ?
What is the function of ALU ?
What role does the output unit play in
a computer ?
What isthe function of main memory ?
‘What ae the measuring urits of memory ?
What are different types of ROM ?
Name some fast storage devices.
Which storage device is considered a
portable device 2
5. Blu Ray Disk
Blu-ray Disc (also known as Blu-ray or BD) is an optical disc
storage media format. Its main uses are high-definition
video and data storage. The disc has the same dimensions
as a standard DVD or CD. While current optical disc techno-
logies such as DVD, DVD + R, DVD * RW, and DVD-RAM
rely on a red laser to read and write data, the new format
uses a blue-violet laser instead, hence the name Blu-ray.
The benefit of using a blue-violet laser (405 nm) is that ithas a
shorter wavelength than a red laser (650 nm), which makes it
possible to focus the laser spot with even greater precision,
‘This allows data to be packed more tightly and stored in less
space, so it’s possible to fit more data on the disc even though
it’s the same size as a CD/DVD. Blu Ray disks of today are
capable of storing upto 128 GB of data.
1.2.6 The System Bus
The system bus (or the bus) is an electronic pathway
composed of connecting cables and that connects the major
components of a computer system. Through system bus,
data and instructions are passed among the computer
system components.
‘© The data carrying part of system bus is called data bus.
© The control instruction carrying part of system bus is called
control bus.
© The memory address carrying part of system bus is called
Address bus.
© A separate type of bus called I/O Bus connects the Input,
Output and other external devices to the system.BY ER NIKHIL SIR
8 COMPUTER SCIENCE WITH PYTHON ~ y
1.3 MOBILE SYSTEM ORGANIZATION
Modern mobile system are tiny computers in your hand. Although they have less computing
power compared to their bigger versions, they handle diverse type of applications such as
making calls through radio signals, offering camera utilities, handling touch sensitive screen,
display audio/video/graphical content but having little battery based power etc.
Display Subsystem
‘Camera Unit
((mage Signal
|] Processor)
Mic Speaker
Figure 1.3 Mobile System Organization
Thus, the system organization of a mobile system has components to handle all these. The block
diagram of a mobile system is as shown here.
Let us talk about these functional components of a mobile system one by one.
A mobile system's CPU handles diverse types of applications but has a little power compared to
computers as mobile systems run on battery power.
1. Mobile Processor (Mobile CPU}
This is the brain of a smartphone. The CPU receives commands, makes instant calculations,
plays audio/video, stores information and sends signals throughout the device.
The CPU of a mobile system has majorly fwvo sub-processor” type:
(#) Communications Processing Unit (ii) Applications Processing Unit (APU)
2. Infact, major subsystems are like processors in themselves eg, Radio Signal Management system can be termed as Fado
signal processor.
Nad.BY ER Nik}
9
CChopter 1: COMPUTER SYSTEM OVERVIEW
() Communications Processing Unit. [Mobile System I/O Unit] This subsystem is
responsible for making and receiving phone calls on a mobile handset. It has a digital
signal processor that helps it work with RF Transceiver and the Audio subsystem.
© Radio Signal Management Unit is responsible
for connecting SIM (which provides a type of
modem) to the base stations through radio these days major components
signals. (SG/LTE/4G based cellular networks). of a mobile system are
(ii) Applications Processing Unit (APU). This subsystem ene cae ee
is responsible for governing, controlling all types of chips consume less power
operations taking place on a mobile system by running compared to other alternatives.
various types of mobile applications (apps).
2. Display Subsystem
‘This subsystem is responsible for providing display facilities, touch sensitive interface and
touch sensitive keyboards.
3. Camera Subsystem
This subunit is designed to deliver a tightly bound image processing package and enable an
improved overall picture and video experience. It has an integrated Image Signal Processor
ensures things like instant image capture, high-resolution support, image stabilization, and other
image enhancements.
4, Mobile System Memory
Like its other counterparts, a mobile system also needs memory to work. A mobile system's
memory is comprised of following 200 types of memories :
( RAM (Random Access Memory). It is the work memory of your mobile system. The
installed mobile apps, when run, are first loaded in the RAM and then executed. These apps
remain in the RAM after you are no longer using them and then they are shifted to background.
‘The more RAM you have on a smartphone, the better the performance and faster the phone will
generally be, RAM does not store information once the device is turned off.
(ii) ROM (Read Only memory). The ROM or Read Only
a Memary is a part of mobile system's internal storage and it
orn. is not accessible for users to write on and is thus referred to
12 as Read Only Memory. The ROM is basically Flash memory
or technically EEPROM (electrically erasable and program-
mable read only memory).
‘This ROM part of a mobile system internal storage is where
1, What are major functional components
of a mobile system ?
2, What is the role of Communication
processor of a mobile system ? operating system resides. It also has some preinstalled apps
4: How does a mobile system manage and _ in this memory sections which cannot be deleted on users’
draw power? end either. This is the reason why you don’t get full internal
4. Whatis the role of display management memory as advertised on the
unit of a mobile system ? Box, because a part of it has.
5. How does memory of mobile function? _been. used to house operating _ RAM memory is volatile, it loses
6 How does the CPU of a mobile system system and other pre-_Hscontents ‘when you switch off
work ? installed apps. peelsBY ER NIKHIL Si
10 COMPUTER SCIENCE WITH PYTHON
5. Storage
The external storage of a mobile system is also called expandable storage. It comes inthe form
of SD cards, or micro SD cards etc. tis the storage which can be removed easily by you and can
be used for storing pictures, musi, videos and the likes. To an extent, even the cioud storage
can also be categorized as external storage.
6. Power Management Subsystem (Battery)
This subsystem is responsible for providing power to a mobile system. The mobile systems
work on limited power provided through an attached battery unit. This subsystem has a battery
management system that works with a battery charger and a battery unit, and provides power
to the mobile system in required form.
1.4 TYPES OF SOFTWARE
A computer system consists of hardware and software for its proper functioning.
‘Hordare represents the physical and tangible components of the computer ie., the components
that can be seen and touched. Input devices, output devices, CPU, hard disk, printer etc. are
examples of computer hardware.
Software represents the set of programs that gover the operation of a computer system and
make the hardware run. Software can be classified broadly into liv categories.
1. System Software 2. Application Software
Following sections discuss system software and application software in details,
1.4.1 System Software
A computer is mere a machine that knows nothing of itself. Rather it requires instructions for
each and everything it performs. These instructions are provided to it through software, The
software that controls internal computer operations (viz. reading data from input devices,
transmitting processed information to the output devices, checking system components, converting
data/instructions to computer understandable form etc.) is known as system software.
The system software can further be classified into wo my
categories : The software that controls
L ting S . . internal computer operations is
ee 2 Tangusge Processor, called System Software.
Let us discuss each one of these individually.
1.4.1 Operating System
The primary goal of an operating system is thus to make the computer system convenient to use
and secondary goal is to use computer hardware in an efficient manner. An operating system is
an important component of a computer system which controls all other components of the
‘computer system. Major components of a computer system are :
1. The Hardware 2. The Operating System An. Operating System is 2
ai whic “
3. The Application program routines (compiler, linkers, Prosfam which acts as ap
database management systems, utility programs) the hardware (ey ol computa
4, The Humanware (users) resources)BY ER Nik}
Chopler 1+ COMPUTER. SYSTEM OVERVIEW 11
where hardwvare provides the basic computing resources, the application program routines define the
ways in which these resources are used to solve the computing problems of the users and the
Operating System controls and coordinates the use of the hardware among the various
application programs for the various users.
‘An operating system's major role is to execute a program. How an operating system executes a
program, is covered in chapter 4,
There are different types of operating systems available today to cater to varied type of
requirements. These are : Single user OS, Multiuser OS, Time sharing OS, Real time OS,
‘Multiprocessing OS, Distributed OS ete.
We are not discussing these operating systems types here as it is beyond the scope of the
syllabus.
1.4.1B Language Processors
A language processor is a special type of a computer software that can translate the source code
into an object code or machine code. Here you should know the meaning of the terms source code
or object code.
‘© A source code refers to the program-code written by a programmer in a high level
programming language (HLL) such as in C, Java, C+ ete,
© An object code refers to a code usually in machine language or binary code, a language
that computer can understand easily and run on hardware.
So, you can safely say that language processors are software that convert source codes into object
codes.
There are three types of language processors : assembler, compiler and interpreter.
(i) Assembler. This language processor converts the program written in assembly language
into machine language.
(ii) Interpreter. An interpreter is a type of system software that translates and executes
instructions written in a computer program line-by-line, unit by unit etc.
(ii) Compiler. A Compiler is another type of system software that translates and executes
| instructions written in a computer program in one go.
Chapter 4 (section 4.3) discusses the working of compilers and interpreters in details.
1.4.2 Application Software
This type of software pertains to one specific application. For instance, a software that can
perform railway reservation functions cannot prepare result for a school.
| ‘These are the programs written by programmers to enable computer to perform a specific task
such as processing words, inventory control, handling calculations and figures, medical
accounting, financial accounting, result preparation, railway reservation, billing etc.
Application software can further be subdivided into four
categories : ‘An Application Software is the
1. Packages 2. Utilities set of programs necessary to
: : carry out operations for a
3. Customised Software 4. Developer Tools aaaBY ER NIKHIL Si
COMPUTER SCIENCE WITH PYTHON .
12
1.4.24 Packages
Only system software does not suffice for efficient use of computers because the system
software exists mostly for the benefit of the computer. Other programs ie,, the application
software are required to make the computer useful for people. Application software has been
written to do almost every task imaginable, from word processing to selecting a college to
attend.
As applications may be numerous (from thousands to millions of them), i
software for each one of them. Rather some general software are designed that may be used by
individual users in the manner it suits their needs and requirements. Such general-application
software are known as packages. Some major and most common categories of general
application software (packages) are :
(Word Processing Software
(iii) Database Management Systems
(2) Graphics, multimedia, and presentation applications.
is not feasible to design
(i Spreadsheets
(jv) Desktop Publishing Software
1.4.2B Utilities
Utilities are those helpful programs that ensure the
smooth functioning of the computer. Utility programs or
simply Utilities are meant to assist your computer.Some _tilties_are_ those application,
ly programs that asistthe computer by
utilities help you backup data, some help remove Propane Mit sll tu comple! by
outdated files or recover data that has been accidentally ike backing up dlsk or scanning /
cleaning viruses or arranging
erased. Some make it easier to find and arrange the
information etc.
information you need. And some help you avoid virus
attacks or clean viruses, if any. In other words, the utility
programs perform house-keeping functions.
Itis an established truth that everything comes with certain pros and cons. Software also are not
an exception to it. Utilities bridge the gaps by helping to solve the problems and maximize your
computer's potential.
‘Some important utilities are being discussed below.
1. Text Editor. This utility program is used for creating, editing text files.
2, Backup Utility. This utility program facilitates the backing-up of disk. Back-up means
duplicating the disk information so that in case of any damage or data-loss, this backed
up data may be used.
3. Compression Utility. This utility program facilitates compression of files. Large files can
be compressed so that they take less storage area.
4, Disk Defragmentor. A file is fragmented when it becomes too large for your computer
to store in a single location on a disk. When this happens, your computer splits the file
up and stores it in pieces. You can use fragmented files, but it takes your computer
longer to access them.
Disk Defragmentor utility program speeds up disk access by rearranging the files and
free space on your computer, so that files are stored in contiguous units and free space
is consolidated in one contiguous block.CChopter 1 : COMPUTER SYSTEM OVERVIEW
BY ER NIKHI
13
5. Antivirus Software. This utility program ensures virus-free work environment. A computer
virus is a malicious computer program that disrupts normal functioning of a computer.
An antivirus software scans your disk for viruses and removes them, if any virus is
found. Moreover, some antivirus software remains present in memory all the time so
that they can detect the viruses (as soon as they occur) and counterattack them.
Application Software
Word processors
‘Spreadsheots ‘System Software Databases
Hardware
Operating ves Presentation
‘System PU, disks, mouse, _— software
printer, te
Language Device
procassors ‘vers
Figure 1.4 Working hierarchy in a computer.
1.4.2C Business Software
Ne
‘This type of software is specifically created software according to « business requirements. This
type of software is developed to meet the general requirements of a business. For instance, a
company wants to computerize its ‘Accounts’ department and gets a software that can serve its
needs, Such a software is business software. There are many readymade business software.
‘These can cater to a variety of business needs. Examples of these software are Inventory
Management System (for managing inventory details of a company), Payroll system (for
handling payroll of a company’s employees), Financial Accounting, Hotel Management and
Reservation System etc. Although there are standard business software available in market, yet
some companies prefer getting customized (tailor-made) software as per their specific
sequirements, However, such softwares cannot be directly
installed at any other user’s workplace as the requirements
3. of the second user may differ from the first and the software
may not fit in the requirements of the new user.
ms
How can computer software be classified ?
What are two categories of system
software ?
What is an operating system ? What is
its role ?
‘What is application software ? What are
the three categories of application
software ?
Differentiate between a compil
interpreter.
What is uauty software ?
What are software Ubraries? How are
they useful to programmers ?
and
1.4.3. Software Libraries
When programmers develop software and programs, they
have a prewritten set of code/functions, classes, scripts etc.
available to do a variety of tasks, which they can use
directly in their code. These predefined sets of codes are
called software libraries. A software library is a predefined
and available to use, suite of data and programming code
in the form of prewritten code/ functions/scripts/classes ete.
that can-be- used in the development of new software
programs and applications.BY ER NIKHIL SIR
14 ‘COMPUTER SCIENCE WITH PYTHON - Xi
The software libraries combine codes/ functions / scripts / classes etc. on the basis of their
‘common domain. In order to use the rewritten functionality, a programmer needs to add that
libraries to its code. For instance, if your software requires some heavy mathematical work then
you need not write the functions/code ete. for
complex mathematical functions. Rather what you —
need to do is that to include/import an available SE Oe Oe Pecan. eel
ee available to use, suite of i
math based software library in your program. Then programming code in the form of prewriten
you can use all the available functions and features code / functions / serots / classes etc. that
of this library in your code without having to can be used in the development of new
rewrite them. You can use a software library in a lsahtware progremasand applications
variety of projects.
For example, Python comes equipped with many software libraries. Some of these are :
| 1, NumPy (Numerical Python). It provides an abundance of useful features and functions
for operations on numeric arrays and matrices in Python.
2. SciPy (Scientific Python). SciPy contains modules for linear algebra, optimization,
integration, and statistics.
| 3. Panda Library. Pandas is a Python package designed to do work with “labeled” and
“relational” data. It is designed for quick and easy data manipulation, aggregation, and
| visualization.
With this we have come to the end of this chapter. Let us quickly revise what we have learnt so
far.
Let Us REVISE
Computers can deliver performance because of an efficient combination of hardware and software.
% While hardware refers (0 physical electronic components of a computer, software represent the recorded
instructions/software that govern its operation.
% Computer organization refers to logical structure of a computer describing their interconnections and work
dependency.
The functional components of @ computer include : input unit, CPU, Memory, Storage Unit, Output Unit
“The Input unit is responsible for obtaining input from user and converting it to digital form.
& The CPU (Central Processing Unit) processes the receiver input as per a set of instructions and produces output.
% The CPU has these sub-components : ALU, Control Unit and Registers.
‘The ALU (Arithmetic of Logic Unit) is responsible for carrying out arithmetic operations and logic operations (e9.,
comparing two values).
| The Control Unit controls or supervises the processing taking place.
% Registers are small data holding areas within CPU that hold data, instructions and memory address during the
Processing.
%& The main memory or memory holds the data and programs for the processing.
“% Main memory can either be ROM or RAM.
% ROM ts read only memory that stores some prewritten instructions.BY ER NIKHI
Chopter 1: COMPUTER SYSTEM OVERVIEW 15
RAM is Random access memory that can be read and written and is used for manipulating data during processing.
The primary memory (RAM) is volatile in nature as all contents are erased as soon as power goes off.
The storage unit stores the contents permanently
Major storage devices are hard disks, CD, DVD, flash drive and Blue-Ray discs.
‘A mobile system handles comple types of operations including input, ouput and processing.
Major functional components of a mobile system are Radio Signal Management subsystem, Display subsystem,
power management subsystem, CPU, Memory and storage subsystems.
Software represents the set of programs that govern the operation of a computer system and make the hardware run.
The software that controls internal computer operations is called system software.
‘An operating system is a program which acts as an interface between the user and the hardware.
Thiove ure diferent types of OSs available —single program OS, multiprogram OS, time-sharing OS, real-time OS,
multiprocessing GS ctr
A language processor converts a program written in high level language to machine language.
Tere ave thive language processors: @ assembler which converts assembly language code to machine code, (ii) compiler
‘and (ii) interpreter which convert high level language code to machine code.
Application software is a set of programs necessary to carry out operations fora specified application.
There are threw categories of application software : @) packages (i) utilities and (ti) customused software.
Utiliy programs assist the computer in maintaining its performance. Some of the utilities are : text editors, backup
utilities, compression utilities, disk defragmentors, and antivirus software,
Customised software is tailor made software according to user's requirements,
Software libraries are sets of prewritten code/functions/classes etc, available to programmers for use in the
development of new code.
Solved Problems
State the basic units of the computer. Name the subunits that make up the CPU, and give the function of each
of the units.
Solution. The basic units of a computer ar
1, Input unit 2. Central Processing Unit (CPU) 3. Output Unit 4. Memory.
‘The CPU has two subunits : the control unit (CU) and the arithmetic logic unit (ALU).
The control unit controls the entire operation being carried out.
‘The ALU performs the arithmetic and logical operations.
What is the function of memory ? What are its measuring units ?
Solution. The memory temporarily holds the data and information during processing.
‘The smallest unit of memory is a byte (8 bits). A byte can store one character in binary form. Other
measuring units are kilobyte (KB) equal to 1024 (2"°) bytes, Megabyte (MB) equal to 1024 KB,
Gigabyte (GB) equal to 1024 MB and Terabyte (TB) equal to 1024 GB
Give examples for each of system software and application software. Explain the function of each type.
Solution. examples of system software are :
() Operating system (ii) Language Processor _(iii) Application SoftwareBY ER NIKHIL SIR
COMPUTER SCIENCE WITH PYTHON - xi
Examples of Operation System are : Single user OS, multiuser OS, batch processing OS, multiprocessing
OS ete.
As the names suggest, single user OS supports single user whereas multiuser OS can support multiple
users. The batch processing OS processes the batches (groups) of jobs (processes given to it) and
‘multiprocessing OS is capable of handling multiple CPUs at the same time.
The examples of language processors are : (i) Interpreter (ii) Compiler (ii) Assembler
An interpreter converts and executes an HLL program into object program line by line whereas a
compiler converts an HLL program into object program in one go and orce the program is error free,
it can be executed later. An assembler converts an assembly language program into object program.
Examples of application software are : (i) Customised Software (ii) General software.
The customised software pertains to the requirements of a specific user for whom the software has
been developed. General software is developed keeping in mind general specifications of a problem.
Why is primary memory termed as ‘destructive write’ memory but ‘non-destructive read” memory ?
Solution. When a memory location is read from in the primary memory, the contents of the memory
word remain the same ; they are not altered. Therefore, a primary memory is termed as ‘non-
destructive read’ memory since the read operation does not destruct the contents of a memory word,
When a write operation takes place, the previous contents of the memory word are overwritten.
Thus, the primary memory is termed as ‘destructive write’ memory as the write operation destructs
the contents of a memory word.
What is the difference between RAM and ROM ?
Solution. RAM refers to random access memory where both read and write operations can take
place. But the RAM is a volatile memory ; its contents are lost when power is tured off.
ROM refers to read only memory where only read operation can take place. The ROM is a
non-volatile memory.
Both RAM and ROM are parts of the primary memory.
What is the role of CPU of a mobile system ?
Solution. A mobile system has to cater to a variety of operations and applications and its CPU has to.
manage all these. Thus the CPU of a mobile system has many sub-processors that help it control and
manage diverse applications. The CPU of a mobile manages all these types of applications and operations:
© Manages communications while connecting to radio transceivers and SIM.
© Manages audio through ADC (analog to digital converter) and DAC (digital to analog converter).
© Manages display and touch sensitive sensors and interface.
© Works in tandem with memory and storage.
What are various categories of software ? *
Solution. There are broadly two categories of software :
1. System Software. This type of software controls internal computer operations. The system
software can further be classified in fa categories :
() Operating System. An operating system isa program which acts as an interface between a user
and the hardware.
(i) Language Processor. This program is responsible for converting an HLL code (High Level
Language code) into machine understandable code.
2. Application Software. An application software is the set of programs necessary to carry out
operations for a specified application.BY ER NIKHIL
Copter 1: COMPUTER SYSTEM OVERVIEW 17
8. What is the difference between an interpreter and a compiler ?
Solution, An interpreter converts an HLL program into machine language line by line and
simultaneously executes the converted line, Also, an interpreter must always be present in the
memory along with the program for its execution. If an error occurs in a line, the line is displayed
and interpreter does not proceed unless the error is rectified.
A compiler converts an HLL program in machine language in one go. If there are errors in the
program, it gives the error list along with the line numbers. Once the errors are removed, error-free
object code is made available and after this compiler is no more needed in the memory.
9, What is application software ? Why is it required ?
Solution, Application software is a software that pertains to one application.
Application software is required because system software cannot carry out the routine jobs
performed by the user which application software can easily do.
To perform various kinds of activities, the application software comes in various categories
(Packages
(i) Utilities
(ii) Business Software
(iv) Developer Tools.
10. Five statements about interpreters and compilers are given below. Study each statement and determine which
of them hold true for a compiler or for an interpreter.
(A) takes one statement at a time and executes it.
(ii)_generates an error report at the end of translation of the tohole program.
i) stops the translation process as soon as the first error is encountered.
(iv) slows speed of execution of program loops.
(2) translates the entire program in one go.
Solution, Interpreter : (i), (ii), (iv); Compiler : (i), (0)
GLOSSARY
——
Bit A binory digit.
oye A group of eight bits.
aw ‘Aithmetic Logic Unit that corries out arithmetic and logical operations.
Aeplication Software pertaining to the operations of o specified application.
Software
Complier Progrom that converts HLL program info machine language in one go ond repors all the errors along
with their line numbers.
Operating System Program which acts os an interface between a user and the hardware.
ou Central Processing Unit thot corries out the given process and supervises the entire operution.
‘Memory ‘An organized collection of cells used to store data and programs in a computer.
‘PROM Erasable programmable read-only memory, @ device that is ultroviclet-erasable and electrically
reprogrammable.
PROM Programmable read-only memory. With o PROM programmer, you can bum in your own programs ond data.
BBY ER NIKHIL SIR
COMPUTER SCIENCE WITH PYTHON — y,
Rondom-occess memory, Itis also called @ read-write memory because you can read the contents
ram
‘of a memory location or write new contents into it.
Rom Read-only memory, (ROM Rymes with Mery) This device provides non-volatile storage of progroms
cond data. You can access any memory location by supplying its address.
Softwore ‘Set of programs that govern the operation of a computer system,
Language Processor Software that converts a high level language code into machine understandable form,
System Software Software that controls intemal computer operations.
Utity Software A schware that oss the computer by performing housekeeping functions.
Assignments
M4
15.
16.
17.
18,
19.
20.
21,
23,
24,
Briefly explain the basic architecture of a computer.
What do you understand by input unit ? What is its significance ? What does computer input consist of ?
What is the function of CPU in a computer system ? What are its subunits ?
What functions are performed by the control unit ? Can we call it the control centre of computer
system ? Why ?
What functions are performed by the ALU ? Is it an independent unit ? If not, which unit does ALU
work in coordination with ?
Distinguish between CPU and ALU.
What is the function of output unit in a computer system ? Give examples of some output devices.
What role does memory play in the functioning of computer system ?
Define each of the following :
(a) byte (b) kilobyte (c) megabyte (d) gigabyte (¢) terabyte.
What is the meaning of the term volatile primary memory ? What can be done to overcome the
problems of volatility ?
Distinguish between internal and external memory
‘What is the role of memory in a computer functioning ? What types of memory does the computer work
with ?
‘What are RAM and ROM ? How are they alike ? How are they different ? What are EEROM, PROM and
EPROM ?
What are major functional components of a mobile system ?
Draw a block diagram depicting organization of a mobile system.
What is the role of power management unit in a mobile system ?
What does the communication processor do ?
‘What is the role of application processing unit in a mobile system ?
How does display subsystem of a mobile system work ?
What is system software ? What role does it play in the functioning of the computer ?
Discuss the role of utility software in the context of computer performance.
What is the importance of an OS ?
How are software libraries useful ? Name some software libraries of Python.
What is the utility of these software ?
() disk fragmentor (ii) backup software.BY ER NIKHIL SIR
Data
Representation
In Wis Charter
2.4 Introduction 2.4 Representing Unsigned Integers in Binary
2.2 Digital Number Systems 25 Binary Addition
2.3 Number Conversions. 2.6 Character/String Representation
2.1 INTRODUCTION
Digital techniques have found their way into innumerable areas of technology, but the area of
automatic digital computers is by far the most notable and most extensive. As you know, a
computer is a system of hardware that performs arithmetic operations, manipulates data, and
makes decisions.
In science, technology, business, and, in fact, most other fields of endeavour, we are constantly
dealing with quantities; so are computers. Quantities are measured, monitored, recorded,
manipulated arithmetically, observed, or in some other way utilized in most physical systems.
In digital systems like computers, the quantities are represented by symbols called digits. Many
number systems are in use in digital technology that represent the digits in various forms, The
‘most common are the decimal, binary, octal, and hexadecimal systems. This chapter discusses
these number systems and the physical representation of digits in computers.ox
BY ER NIKHIL Sif
COMPUTER SCIENCE WITH PYTHON - xi
DIGITAL NUMBER SYSTEMS
In digital representation, various number systems are used. The most common number systems
used are decimal, binary, octal, and hexadecimal systems. Let us discuss these number systems
briefly.
2.2.1 Decimal Number System
2.2.2
The decimal system is composed of 10 numerals or symbols (Deca means 10, that is why this
system is called decimal system). These 10 symbols are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ; using these
symbols as digits of a number, we can express any quantity. The decimal system, also called the
base-10 system because it has 10 digits, has evolved naturally as a result of the fact that man has
10 fingers.
The decimal system is a positional-nalue system in which the value of a digit depends on its
position. For example, consider the decimal number 729. We know that the digit 7 actually
Tepresents 7 iti/cis, the 2 represents 2 (cis, and the 9 represents 9 1i!s. In essence, the
7 carries the most weight of three digits; itis referred to as the most significant digit (MSD). The 9
carries the least weight and is called the least significant digit (LSD).
Consider another example, 25.12. This number is actually equal to (2 tens plus 5 units plus
1 tenths plus 2 hundredths) ie., 2x10+5x1+ ik +2x2 75 The decimal point is used to
separate the integer and fractional parts of the number.
More rigorously, the various positions relative to the decimal point carry weights that can be
expressed as powers of 10. This is illustrated in Fig. 2.1 where the number 2512.1971 is
represented. The decimal point separates the positive powers of 10 from the negative powers.
‘The number 2512.1971 is thus equal to
2107 +5x1 1x10! 210° 41x10 49x10 7x10 +1x10~*
In general, any number is simply the sum of the products of each digit value and its positional
value.
The squence of decimal — Positional
numbers goes 280, 12,3 4, values—> 10° 10? 10! =10° 107 107 10° 10
is)
5,6,7,8,9,10,11,12,13,14 “MM » yy 4 4 iy uiy
15, 16, 17, 18, 19, 20, 21.... See 2 5 1 2 q 7 9 7 E i
after 9, each successive
number is a combination of T t t
Msp decimal isc
two (or more) (unique) nt
symbols of this system.
Figure 2.1 Positional values in decimal numbers.
Binary Number System
Unfortunately, the decimal number system does not lend itself to convenient implementation in
digital systems. For example, itis very difficult to design electronic equipment so that it can work
with 10 different voltage levels (each one representing one decimal character, 0 through 9).
On the other hand, itis very easy to design simple, accurate electronic circuits that operate with
only two voltage levels. For this reason, almost every digital system uses the binary number
system (base 2) as tie basic number system of its operations, although other systems are often
used in conjunction with binary.BY ER NIKHI
Chapter 2 : DATA REPRESENTATION, 21
In the binary system there are only two symbols or possible digit values, 0 and 1. Even so, this
base-2 system can be used to represent any quantity that can be represented in decimal or other
number systems.
The binary system is also a positional-value system, wherein each binary digit has its own value
or weight expressed as a power of 2. This is illustrated in Fig. 2.2.
Here, placestotheleftofthe Posional 23 929! gt? gt
binary point (counterpartof MS Py yy tg
the decimal point) are posi- I
tive powers of 2 and places LE NOP rh
: 7 t
to 7 night ae negative Me binary LsB
pow » The number (wast significant i) ait (Coast Sionitcant Bt)
1010.0101 is shown repre-
sented in the figure. Figure 2.2 Positional values in binary numbers.
To find the decimal equivalent of above shown binary number, we simply take the sum of the
products of each digit value (0 or 1) and its positional value :
10100101, =(1 x 23) + (0x 22) +(1 x 2!) #(0« 2°) +(0x 2“) + (1x27) +(0x2 9) +(x 24)
8+0+2+0+0+0.25+0+0.0625 =10.3125 9
Notice in the preceding operation that subscripts (2 and 10) were used to indicate the base in
which the particular number is expressed. This convention is used to avoid confusion whenever
more than one number system is being employed.
In the binary system, the term Binary digit is often abbreviated to the term bit, which we'll use
henceforth. As you see in Fig. 2.2, there are 4 bits to the left of the binary point, representing the
integer part of the number, and 4 bits to the right of the binary point, representing the fractional
part. The leftmost bit carries the largest weight and hence, is called the most significant bit (MSB).
The rightmost bit carries the smallest weight, and hence called least significant bit (LSB).
The sequence of binary numbers goes as 00, 01, 10, 11, 100, 101, 110, 111, 1000, - - -- - -. The
binary counting sequence has an important characteristic. The unit's bit (LSB) changes either
from 0 to 1 or 1 to 0 with each count. The second bit (two's (2) position) stays at 0 for
two counts, then at 1 for two counts, then at 0 for two counts, and so on. The third bit (four’s
(2) position) stays at 0 for four counts, then at 1 for four counts, and so on. The fourth bit
(cight’s (2°) position) stays at 0 for eight counts, then at 1 for eight counts. [f we wanted to count
farther we would add more places, and this pattern would continue with 0s and 1s alternating,
in groups of 2"~",
2.2.3. Octal Number System
‘The octal number system is very important in digital computer work, The octal number system.
has a base of eight, meaning that it has eight unique symbols :0, 1, 2, 3, 4,5, 6, and 7. Thus, each
digit of an octal number can have any value from 0 to 7.
The octal system is also a posi- Positional
tional value system, whercin values» g> gs? s' 8”! 8 8B
cach octal digit has its own eM) yy oy oy dL
value or weight expressed asia Jee
power of 8 (See Fig. 2.3). The :
places to the left of the octal
Octal point
Figure 2.3. Positional values in Octal numbers.BY ER NIKHIL SIR
2 COMPUTER SCIENCE WITH PYTHON — x1
it i id places to
point (counter-part of decimal point and binary point) are postive powers se 8 andpl nent the
Fight are negative powers of 8. The number 3721.2406 is shown rePr® 7
1 number, simply take the sum of products
To find the decimal equivalent of above shown octal
of each digit value and its positional value :
-1) (4x87) 4(0x2*) + (6x8)
3721.2406, = (3% 8°) + (7 x 82) +(2x8!) +(1x 8°) +(2%8
Ju S124 7x 64 42x 8-1 x1 + 2x 0.125 +4 x 0.015625 + 0+ 6x 0.000244
71536 4 448 + 16-41 + 0.25 + 0.0625 +-0-+ 0.001464 = 2001.313964 19
6,7, 10, 11, 12, 13, 14, 15, 16, 17, 20, 21, 2:
two or more unique symbols of octal
‘The sequence of octal numbers goes as 0, 1,2, 3, 4,5,
See each successive number after 7 is a combination of
system.
‘The hexadecimal system uses base 16, Thus, it has 16 possible digit symbols. It uses the digits 0
through 9 plus the letters A, B, C, D, E, and F as the 16 digit symbols.
Just like above discussed systems, hexadecimal system is also a positionalvalue system, wherein
‘each hexadecimal digit has its own value or weight expressed as a power ‘of 16, (See Fig. 2.4). The
digit positions in a hexa-
decimal number have weights
‘as shown in Fig. 2.4. igh vcr] 1? 16? | 16! | 16° | 167 | 167 | 16° | 16+
Following table 2.1 shows the feds
relationships between hexa- rae
a octal, decimal and Figure 2.4 Positional values in hexadecimal numbers.
Table 2.1 Relationship between Various Number Systems
Hexadecimal Octal Decimal Binary
0 0 0 0000
1 1 1 0001
a 2 2 0010
3 3 3 0011
4 4 4 0100
5 5 5 0101
6 6 6 0110
7 7 7 oul
8 10 8 1000
* ob 9 1001
A BR w 1010 Note that each hexadecimal digit
B 3 0 1011 represents a group of four binary
c 4 2 1100 digits. It is important to remember
D 18 B 01 that hex (abbreviation for
E 6 “ 1110 hexadecimal) digits A through F
are equivalent to the decimal
17 15, 111
E values 10 through 15.
thChapter 2 : DATA REPRESENTATION
23
SReES es Aree
NUMBER CONVERSIONS
BY ER NIIKH|
23
The binary number system is the most important one in digital systems as it is very easy to
implement in circuitry. The decimal system is important because it is universally used to
outside a digital system.
represent quanti
In addition to binary and decimal, octal and hexadecimal number systems find widespread
application in digital systems. These number systems (octal and hexadecimal) provide an
efficient means for representing large binary numbers. As we shall see, both these number
systems have the advantage that they can be easily converted to and from binary.
Table2.2 Powers of 2
33
o
134
536
17
294
179
79
554
108
27
435
870
741
483
967
ase
Bees
476
2
16
128
256
512
024
048
096
192
768
536
on
ua
288
576
Bees
216
432
864
728
456
912
624
648
296
26
RReBReSs
2
10
05,
025
025]
0.082
031
0015
007
0.003
0.001
0.000
0.000
0.000
0,000
0.000
10,000
0.000
0.000
6.000
6.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0,000
0.000
0,000
0.000
0.000
0.000
0.000
0.000
0.000
Bitior
812
906
953
976
488
24
12
061
030
015
07
003
oor
‘000
000
000
Egggegegeg2zee¢s
g22288
562
281
40
035,
517
258
os
814
953,
476
238
19
089
029
ou
2288
000
Bua
312
578
789
394
348,
674
837
418
604
901
450
m5
862
931
465
232
16
058,
029
ons.
125
062
531
265
632,
316
158
579
289
ou
3
161
580
290
a5
661
830
a5,
103
551
Bua
812
&
203
101
Beige
596
298
149
574
287
32
88
915
Ina digital system, three or four of these
number systems may be in use at the
same time, so that an understanding of
the system operation requires the ability
to convert from one number system to
another. This section discusses how to
perform these conversions. So, let us
discuss them one by one.
2.3.1 Decimal
There are fwo procedures for converting
(integers) from decimal to binary.
-Binary Conversion
The first method requires a table of
powers of 2 (table 2.2). Because of this
restriction, it is more useful for small
numbers where these powers have been
memorized. Starting with the decimal
number to be evaluated, obtain the
largest power of 2 from the table without
exceeding the original number. Record
5 this. Then subtract the table obtained
2) number from the original number.
aze Repeat the process for the remainder,
te, and continue until the remainder is zero.
wey eas|__ Finally, add the binary numbers
son gia 7g] obtained from the table. The result is the
B47 656 25] answer.
923 828 125|
461 914 0625
230-957 031 25
615 478 515 625
307 739 257 812.5)
653 869 628 906 25
826 934 814 453.125
913 487 407 226 562 5)
456 733 703 613 281 25)
228 366 851 806 640 625
[aBY ER NIKHIL SIR
COMPUTER SCIENCE WITH PYTHON 9
EXAMPLE 21 Convert 43g to binary.
Solution. From table 2.2, 32 is the largest number without exceeding 43.
32 =100000
(2% =32 i, put 1 at (5+1) th position and 0, at all other positions. Thus 32; =100000,)
43-32-11
From the table, 8 (2%) is the largest number without exceeding 11.
8=1000
2 =8iie, put 1 at 3+1)" position and 0, at all other positions. Thus 81) = 1000.)
1-8-3
From the table, 2 is the largest number without exceeding 3.
2=10
(2? =2, thus 2y9 =10,)
3-2-1 t
1 is the largest number without exceeding 1
q=1
Add all the binary numbers obtained ie,
Thus 434) =101011,
EXAMPLE 2.2 Convert 2009 to binary.
Solution. First largest number is 128.
Longest number
128=10000000
200-128=72 64= 1000000
8= 1000
001000
~ t
Therefore, 200; = 11001000,
The second method of converting decimal to binary is repeated-division method, In this
method, the number is successively divided by 2 and its remainders recorded. The final binary
result is obtained by assembling all the remainders, with the last remainder being the most
significant bit (MSB).BY ER NIKH|
CChopter 2 : DATA REPRESENTATION 25
EXAMPLE 2.3. Convert 43,9 to binary using repeated division method.
Solution.
Repeated Division Remainders
2 43
2 21 1 1sB
2 10 1
2 5 0 | wet in tis
2 7 1 order
2 1 0 |
0 1 MsB
Reading the remainders from the bottom to the top,
43,9 =101011, (compare with result of example 2.1)
EXAMPLE 2.4 Convert 200,o to binary using repeated division method.
Solution.
Remainders.
2|__20
2100 0 188
2% 0
2 | 35 0
22 1
2[ 6 o
2[ 3 0
3f 4 1
0 1 MSB
Reading the remainders from the bottom to the top, the result is: 200; =11001000,
On paper you may even compute the 85/2 .
Senwereion jas _depicied_,ftiroueh a "4. Least significant bit (LSB)
following example. (As you can see a pe
that this is just another way of v =
representing the repeated division.) pare
EXAMPLE 2.5 Convert 8549 to binary using
repeated division method.
Solution. (See on the right) fe
Q- Quotient and zk
R- Remainder YN
Az
8510
1010101, YN
1: BY ER NIKHIL Sil
26 COMPUTER SCIENCE WITH PYTHON —
2.3.2 Binary-to-Decimal Conversion
The binary number system is a positional syste
weight based on its position relative to the LSI
decimal equivalent simply by summing together
binary number which contain a 1. To illustrate, consi
sm where each binary digit (bit) carries a certain
B. Any binary number can be converted to its
the weights of the various positions in the
ider a binary number 11011,
1] 1| o] 1] 1 | (inary)
‘Add positional weights
foral1S > 244294042) +29=16+8+241
= 27 49 (decimal)
Let's try another example with a greater number of bits i¢., 10110101
1] of 1] 1] of 1} 0] 2
Adding positional weights
of all's, > 27 £0425 +24 40427 +0429 =18lig
Note that the procedure is to find the weights (ie, powers of 2) for each bit position that
contains a 1, and then to add them up. Also note that the MSB has a weight of 2” even though itis
the eighth bit; this is because the LSB is the first bit and has a weight of 2°.
The above method will always provide the correct decimal representation of a binary number.
There is a second method, called the dibble-dobble method, that will also provide the solution. To
use this method, start with the left-hand bit. Multiply this value by 2, and add the next bit to the
right. Multiply the result value by 2, and add the next bit to the right. Stop when the binary
point is reached.
To illustrate,
11011, (binary)
Copy down the leftmost bit : 1
Multiply by 2, add next bit (2x1) +1 =3
Multiply by 2, add next bit (2x3) + 0 =6
Multiply by 2, add next bit (2x6) +1 =13,
Multiply by 2, add next bit (2x13) #1=27 2 MOM, =27
Let us try another example, 110100,
‘The leftmost bit : 1
Multiply by 2, add next bit (2x1) +1 =3
Multiply by 2, add next bit (2x3) +0 =6
Multiply by 2, add next bit (2x6) +1 =13
|! Multiply by 2, add next bit (2x13) + 0 =26
Multiply by 2, add next bit (2x26) + 0 =52 4 110100; = 5249BY ER NIKHI
Chapter 2 : DATA REPRESENTATION, 27
2.3.3 Decimal-to-Octal Conversion
A decimal integer can be converted to octal by using the same repeated-division method that
we used in the decimal-to-binary conversion, but with a division factor of 8 instead of 2. An
example is shown below :
Remainders
| __266___
{ 33 2
0 4
Reading up, 26649 = 4125
Note that the first remainder becomes the least significant digit (LSD) of the octal number, and
the last remainder becomes the most significant digit (MSD).
2.3.4 Octal-to-Decimal Conversion
An octal number, then, can be easily converted to its decimal equivalent by multiplying each
octal digit by its positional weight. For example,
372, =3x (87) +7 x (8!) +2x (8
=3x64+7x842x1 = 2509
Another example :
24.65 = 2x (81) +4 x (8°) +6x(8“) = 20.7549
2.3.5 Octal-to-Binary Conversion
The primary advantage of the octal number system is the ease with which conversion can be
made between binary and octal numbers. The conversion from octal to binary is performed by
converting each octal digit to its 3-bit binary equivalent. The eight possible digits are converted
as indicated in table 2.3.
Table 23. Binary Equivalents of Octal Digits
Octal Digit 0 1 2 3 4 5 6 7
Binary Equivalent | 000 0011001001010
Using these conversions, any octal number is converted to binary by individually converting each
digit. For example, we can convert 472, to binary using 3 bits for each octal digit as follows :
4 7 i
L L
100 m1 010
Hence, octal 472 is equivalent to binary 100111010. As another example, consider converting,
5431 to binary :
ss 4 B--a
4 ououoe
101 100 o11 001
Thus, 5431, = 101100011001.BY ER NIKHIL Sif
COMPUTER SCIENCE WITH PYTHON ~ x
The same process applies equally on fractions. For example, ae
3.01 The octal to binary conversion
ai,.- L takes place using 3bit sub.
oe on OOl stitution for each octal character,
pom
By = 011.001,
2.3.6 Binary-to-Octal Conversion the forego
Converting from binary integers to octal integers is simply the reverse of the loreg0ing process.
The bits of the binary ieee grouped into groups of three bits starting at the LSB. Then each
group is converted to its octal equivalent (table 2.3). To illustrate, consider the conversion of
1001110102 to octal.
100 111 o10
t t +
4 7 25
‘Sometimes the binary number will not have even groups of 3 bits. For those cases, we can add
‘one or two 0s to the left of MSB of the binary number to fill out the last group. This is illustrated
below for the binary number 11010110.
110
011 010
dinidetinmsomia ZO £ ¥ L
it group of 3 bits
oe
Note that a 0 was placed to the left of the MSB in order to produce complete groups of 3.
‘The same process applies on fractions. But after the binary point, zeros are added to the right.
- For example x
101100101, = 010 110, 010, 100
2 6 2 «
2 zeros aed hore 0
10110.0101 = 26.245 make ta group of 38s
Note that, after the binary point, the groups of 3 bits are made starting from left-to-right. Thatis
why, we added two zeros to make a group of three bits as the last group had only 1.
2.3.7 Decimal-to Hex Conversion
Recall that we did decimal-to-binary conversion using repeated division by 2, and
decimal-to-octal using repeated division by 8. Likewise, decimal-to-hex conversion can be done
using repeated division by 16. For example, y
To convert 423; to hex, Similarly, to convert 214 jg to hex,
Remainders Remainders
16] 423 16 | 214
6|_% 7 wl 3 6
16 [1 A | €0=Ac eB
? 1 to Ae) 0 D — 30= De)
1} Reading up, 42319 =147 1g Reading up, 2144 = D6 4,
Note that any remainders that are greater than 9 are represented by letters A through F-BY ER NIKHI
CChopter 2 : DATA REPRESENTATION 29
9.3.8 Hex-to-Decimal Conversion
A hex number can be converted to its decimal equivalent by using the fact that each hex digit
position has a weight that is a power of 16. The LSD has a weight of 16° =1, the next higher digit,
has a weight of 16'=16, the next higher digit has a weight of 16* =256, and so on. The
conversion process is demonstrated in the examples below :
3561, =3x 16? +5x 16! +6x16°
=768 +80+6
= 85449
2x16? +10x 16! +15x 16°
512+160+15
= 68749
Note that in the second example the value 10 was substituted for A and the value 16 for Fin the
conversion to decimal. To convert a fractional number,
56.0814 =5% 16! +6x16° +0167! +8x16~*
0 +6 +048 / 256 = 86 + 0.03125
= 86.03125,9
2AR,
2.3.9 Binary-to-Hex Conversion
Binary numbers can be easily converted to hexadecimal by grouping in groups of four starting
at the binary point.
EXAMPLE 2.6 Convert 1010111010, to hexadecimal.
Solution. Group in fours 10,1011,1010
Convert each number 2 BA
Thus, the solution is 2 BA.
EXAMPLE 2.7 Convert 10101110.0101112 to hexadecimal.
Solution. Groups in fours (inserting zeros before MSB or in the end, wherever required)
1010, 1110 . 0101, 1100
A E..5 €
10101119.010111, = AESC ys
2.3.10 Hex to Binary Conversion
Like the octal number system, the hexadecimal number system is used primarily as a
“shorthand” method for representing binary numbers. Itis a relatively simple matter to convert
a hex number to binary. Each hex digits converted to its 4-bit binary equivalent (table 21). This
is illustrated below for 9F2,¢. Pore ad
9 F 2
9F 245 =
+ ‘ + Hex to binary conversion takes
lace using &-bit substitution for
1001 1111 0010 Ke Oca
=100111110010, SERRE ESBY ER NIKHIL Si
COMPUTER SCIENCE WITH PYTHON ~
, 30
Similarly, 3A6,6 = 3 A c eee
+ + 4 The hexadecimal and octal
oon —1010—=S«0110 codes are used as shorthany
_ means of expressing large bin
= 001110100110, airs ta
Consider another example
BBFSC\y= 3 B F e c
1 4 L + L
ool 1011 m1 101 1100
= 001110111111.01011100,
Converting from Any Base to Any OTHER Base
‘As demonstrated in earlier examples and the table below, there is a direct correspondence
between the number systems : with three binary digits corresponding to one octal digit; four
binary digits corresponding to one hexadecimal digit, which you can use to convert from one
number system to another.
Table 2.5 Correspondence of Binary, Octal and
Table 2.4 Correspondence of Binary and
Hexadecimal Number Systems
Octal Number Systems
BIN ocr DEC BIN HEX ocr DEC.
000 0 o 0000 0 00 o
001 1 1 001 1 1 1
oo10 2 02 2
o10 2 2
oot 3 a 3
on 3 3 100 4 a _
300 4 4 o1o1 5 05 5
101 5 5 ono 6 06 ‘
0 6 6 on 7 7 7
8
m1 7 7 1000 8 10
1001 9 u 9
| 1010 A 2 10
For conversion from base 2 on i 3 ii
to base 8, we use groups of ;
three bits and vice-versa. 1100 c “4 i
no. D 15 B
amo E 16 4
m1 F wv B
J For conversion from base 2
} to base 16, we use groups
of four bits and vice-vers*
Ey ONTOS ibd eens eaeBY ER NIKH
‘Chopter 2 + DATA REPRESENTATION
31
Let us consider some more examples regarding the same, ie,, converting from any number
system to another.
EXAMPLE 2.8 Convert 1948.B6,, to Binary and Octal equivalents.
Solution.
Hexadecimal 1 9 4 8 . B 6
Binary 0001 1001 0100 1000 1011 0110
(By converting each individual Hex digit to equivalent 4 digit binary from above table 2.5)
“ 1948.B6 y¢ = 0001100101001000.10110110 >
New Octal number can be generated from above Binary equivalent i.., as follows :
Binary 0 001 100 101 001 000 . 101 101 100
Octal 145 10.5 5 4
(By creating groups of 3 binary digits and converting them into equivalent octal no.)
1948.B6,, = 14510.554.
EXAMPLE 2.9 Convert 75643.5704, to hexadecimal and binary numbers.
Solution, We shall convert it in following way :
() From octal to binary — by representing each octal digit to 3 digit binary number.
(i) From the complete binary number, we shall create groups of 4 binary digits around the
decimal point.
(iii) Convert each 4-digit-binary group to equivalent hex digit.
Octal 7 5 6 4 3 . 5 7 0 4
Binary 111 101 110 100 O11 . 101 111 000 100
75643.5704, = 111101110100011.101111000100
Binary 0111 1011 1010" OoIL « 1011 1100 O10
Hexadecimal 7 B.A, De BLS
75643,5704, = 7BA3.BC4 1g
After learning about various digital number systems, one must know how the data is
represented in computers.
2.4 REPRESENTING UNSIGNED INTEGERS IN BINARY
An unsigned integer can be either a positive integer or zero but never a negative integer. Before
we discuss how unsigned numbers are represented, consider a single digit decimal number :
© Inasingle decimal digit, you can write a number between 0 and 9 (maximum number is 9).
© In two decimal digits, you can write a number between 0 and 99 (maximum number is 99).
‘© In three decimal digits, you can write a number between 0 and 999 (maximum number is 999),
and so on.“Table 2.6 Ranges of Unsigned integers Represented through n-bits
25
BY ER NIKHIL SIR
COMPUTER SCIENCE WITH PYTHON
Since 9 is equivalent to 10! —1 ; 99 is equivalent to10* -1 999 is equivalent to 10° ~1¢4¢, in
1 decimal digits, you can write a number between 0 and 10" —1.
Analogously, in the binary number system,
an unsigned integer containing n bits can have a value between 0 and 2” — 1 (ie out of 2”
different values).
This fact is one of the most important and useful things to know about computers.
An mbit pattem can represent 2” distinct integers. An bit unsigned integer can represent
integers from 0 to 2" -1, as tabulated below :
n (bits) | Minimum value ‘Maximum Value
8 0 28-1 (=255)
16 0 2'* 1 (=65,535)
32 0 2% _1 (= 4294,967295) (9+ digits)
64 0 2 1 (= 18,446,744,073,709,551615) (19+ digits)
‘Thus the unsigned integers are represented by storing their equivalent binary code through n
bits, where n can be 8 or 16 or 32 or 64.
BINARY ADDITION
ALUs don’t directly work upon decimal numbers ; rather they process binary numbers as a
computer can understand only binary numbers. There are five basic cases for binary addition
that must be understood before going on. These are :
Case 1: 0+0=0
ie., addition of two binary 0's (zero) results into a binary 0 (zero).
Case 2: O+1=1
ie, addition of a binary 0 (zero) and a binary 1 (one) results into binary 1 (one).
Case 3: 140-1
ie, addition of a binary 1 (one) and a binary 0 (zero) results into binary 1 (one).
Case4: — 141=10
ie., Binary 1 + Binary 1 equals Binary 10. Or we can say that in binary numbers, one
plus one equals zero (0), carry one (1).
Case5: 1+141=11
ie, Binary 1 + Binary 1 + Binary 1 equals Binary 1, carry Binary 1.
Let us summarize these rules
0+0=0
O+1=1
14+0=1
1+1= 10 {0 with carry!)
14141= 11 [1 with carry 1]BY ER NIKHIL SIR
CChopler 2 : DATA REPRESENTATION 33
Decimal Addition
Let us now perform binary addition on bigger binary numbers. The binary numbers are also
added column-by-column just like decimal numbers. Also, the way results larger than largest
decimal digit are carried-over, in binary addition, results larger than 1 are also carried over.
For example,
This is carried over as $+7 = 12iwhich is more than 9,
1 hence carried over.
15
a2
Similarly, Binary Addition will be
Ae
aiid
1111 (Equivalent of 1559)
11011 Equivalent of 279)
101010 (Equivalent of 42,5)
Let us perform another addition, step-by-step for
11100
+11010
Start with the least significant column i,, the right most column to get
11100
11010
0
In all examples, 0+ 0 gives 0.
Next, add the bits of the second column (second from right) as follows :
11100
#11010 1111
10
This time, 0+1 gives
‘The addition in third column gives
11100
#11010
710
In this case, 1+0 results in
11100
+11010
(carry 1)
0110 feanya}34
As you see, 1 +1 produces 10 i.e,
Finally, the last column gives
0 with a carry of 1.
1 + Caries
11100
+11010
110110
Here, 1+1+1 (previously generated carry) results in 11, recorded as 1 with a carry to the next
higher column,
S21
1. What are the bases of decimal, octal,
binary and hexadecimal systems ?
2 What is the common property of
ecimal, octal, binary and hexadecimal
number systems ?
3. Complete the sequence of following
binary numbers : 100, 101, 110,
4. Complete the sequence of following
octal numbers : 525, 526, 527,
5. Complete the sequence of following
hexadecimal numbers : 17, 18, 19,
Convert the following binary numbers
to decimal and hexadecimal :
(@) 1010) 111010 (¢) r01011111
(@ 1200 (¢) 10010101 (11011100
7. Convert the following decimal numbers
6
to binary and octal :
(@) 23 (&) 100 (@) 145
@19 (e121) 161
8. Convert the following hexadecimal
numbers to binary :
(2.6 © (6) Ao? (@) TABS
(BE) BO) BC
9. Convert the following binary numbers
to hexadecimal and octal
(@) 10013011101
(@) as12011101011011
(6) 1010131010111
(a) 1010110110111
(© 1020111011011
(p 1111101110101
BY ER NIKHIL Si
COMPUTER SCIENCE WITH PYTHON -
~s Exampte 2.10 Add the binary numbers 01010111 and 00110101.
Solution, If you add the bits column by column as earlier
explained you will get
144
14
+ Carries
O1010141
+00110101
100
10001
EXAMPLE 2.11 Add the bi
Solution. 17
1011
+ 110
10001
jinary numbers 1011 and 110.
<— Caries .
Exampte 2.12 Add binary numbers 11110 and 11.
Solution. 414
— Canes
11110
1
10000
1
7
ExamPLe 2.13 Add binary numbers 11.01 and 101.11,
Solution. 144
1 Carries
11.01
101.11
1001.00
2.6
CHARACTER/STRING REPRESENTATION
In addition to numerical data, a computer must be able to
handle numerical information. In other words, a computer
should recognize codes that represent letters of the
alphabet, punctuation marks, and other special characters
as well as numbers. These codes are called alphanumeric
codes. A complete alph:
‘anumeric code would include the 26
lowercase letters, 26 uppercase letters, 10 numeric digits, 7
punctuation marks, and anywhere from 20 to 40 other
characters, such as 4, /, , %, *, and so on, We can say that
an alphanumeric code represents all of the various
characters and functions that are found on a standard
typewriter (or computer) keyboard,