0% found this document useful (0 votes)
2K views546 pages

CP Text

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views546 pages

CP Text

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 546

Computer

Fundamentals and
Programming in

— Reema Thareja |
Computer
Fundamentals and
Programming in

SECOND EDITION

Reema Thareja
Assistant Professor
Department of Computer Science
Shyama Prasad Mukherji College for Women
University of Dethi

OXFORD
UNIVERSITY PRESS
OXFORD
UNIVERSITY PRESS

Oxford University Press is a department of the University of Oxford.


It furthers the University’s objective of excellence in research, scholarship,
and education by publishing worldwide. Oxford is a registered trade mark of
Oxford University Press in the UK and in certain other countries.

Published in India by
Oxford University Press
YMCA Library Building. 1 Jai Singh Road, New Delhi 110001, India

© Oxford University
Press 2012. 2016

The moral rights of the author/s have been asserted.

First Edition published in 2012


Second Edition published in 2016

All rights reserved. No part of this publication may be reproduced, stored in

poe ee
a retrieval system, or transmitted, in any form or by any means, without the
i ifOxford University Press, ited

rightsorganization. Enquiries ncerning reproduction outside the scope of


cot stthe
souldbe sent to
the RightsDepartment, OxfordUniversityPres at the
address above.

You must not circulate this work in any other form


and you must impose this same condition on any acquirer.

ISBN-13: 978-0-19-946373-2
ISBN-10; 0-19-946373-5

eISBN-13 (eBook): 978-0-19-909037-2


elSBN-10 (eBook): 0-19-909037-8

in Times New Roman


by Ideal Publishing Solutions, Delhi
Printed
in India by Magic International (P) Ltd., Greater Noida
bocaoronrehmpepneary erally adap ead whaler
pha University Press in good faith and for inf n only.
Oxford University Press disclaims any responsibility for the material contained therein.
1 dedicate this book to my family
and
my uncle Mr B.L. Theraja
Features of
.
Sag
$: G4aprcuction to Computers
* yor > Yat
bore aan Comprehensive Coverage
nos q aterm
Chapters provide a comprehensive coverage of topics
bee ana ranging from basics of computer hardware and
ee software to the basics of C programming

fiber Systems and c Amays


ee ist S

Keys such as Shift, Ctrl, and Alt are called modifier keys
because they are used to modify the normal function of a
key. For example, Shift + character (lowercase) makes the
Notes and Programming Tips computer display the character in upper case.
Notes highlight important terms and concepts,
and programming tips educate the readers about
common programming errors and how to avoid Programming
Tip:
Strings cannot be
them manipulated with
arithmetic or other
operators available in
C boundaries.

POINTS TO REMEMBER

* Acomputer is an electronic machine that accepts data Points to Remember


and instructions and performs computations on the
Summary points at the end of each chapter help
data based on those instructions.
* Computers are used in all interactive devices, such as readers to revise all the important concepts explained
cellular telephones, GPS units, portable organizers, in the chapter
ATMs, and gas pumps.

GUDSSARY
Glossary eee pa nee at rtsayat oeet
cae mereSta
meet owe sree Hataati teat
Includes a list of key terms along with their definitions Come mate nage Snr ene
ane mae owtee© ot paeny Oe
for a quick recapitulation of important terms learned ee
ee anadieaddeed
in all chapters fe ees ore eS
Cans met capes The mee oteat
the Book
CASE STUDY 1: Chapters
9and10
a attire Case Studies
Select chapters on C include case studies that
CASE STUDY 2: Chapter 12
show how C can be used to create programs
demonstrating real-life applications

2. Write a program to print Hello World, using pointers.


#include <stdio.h>
int main()
Programming Examples (
char *ch « “Hello World";
About 250 C programs are included, which printf("Xs", ch);
demonstrate the applicability of the concepts learned return 0;
)
Output
Hello World

.4 +
» =
Sa. to Objective
tions Objective Questions
Includes comprehensive exercises at the end of each
chapter to facilitate revision—Answers to these
questions are provided in Appendix F at the end of
the book

EXERCISES
Exercises
Includes plenty of program code-related programs
at the end of relevant chapters, which require the
readers to find the output of a given code, the
functionality of a given loop, or errors in a given
program code
Companion Online Resources
SOOKE
Visit india.oup.com/ores/9780199463732 to access
both teaching and learning solutions online.

Online Resources
The following resources are available to support the
faculty and students using this text:

For Faculty
* PowerPoint presentations
* Solutions manual
* Projects

For Students
* Multiple-choice Questions
* Model Question Papers
* Codes of chapter-wise programming examples

Steps to register and access Online Resources

‘Step5: Signinwithyour Oxford 10 | Step 7: Fill in your details


Sign i eh pre Ontors 10 | + Fillthe detated
registration form with
correct particulars,
wes * Fields marked with ‘**
lothe form are
mandatory
— © Upitate
© AOVANCED SEARCH eee
» KEYWORDS a,
‘AuTHOR
Tme Step 6:ifyoudenethaveanOxford ID,register withws ‘Step& Validation
SUBTITLE © We shallrevert toyou
PUBLICATION OATE — within 48 hours after
vwerityingthedetails
‘Step 3: Sebect tite on provided by you. Once
© Select Preduct — wadsted, please login
© Select CGntine Resources «sing yourusername
| —_—
tavsorcinie vi
and password
and

Step 9:Confirmation
© Youwil receivea
confemation omyour
‘Step 4:ViewResources gray = =
© Chik on"Viewat Fear
resources* Step 20;Visitusagain
oa, © Goto indiacup-com
aS © Sign in withOuferdiO
Step 11: Visityourlicensed products Step 12:Download Resources
* Goto “Resources” section © Git onthetitle
. View orine resources
— Resources
© Select resource type

=—-- -
© Oownioad the resource you require
Preface to the Second Edition
Information technology (IT) is the buzzword in the 21st century. It has revolutionized the way we think and irreversibly
changed our everyday existence. Computers form the backbone of information technology affecting all aspects of our
lives, They are not only used for general computing but also for performing tasks such as booking railway and airline
tickets, designing a building, training a player, and practicing landing of an airplane. The use of computers has become so
widespread that almost all electrical and electronic devices such as washing machines and air conditioners have a small
embedded computer within them. Even the smartphones are connected to the Internet.
Learning computers is no longer meant only for students pursuing 4 career in engineering and technology, but is also
mandatory for students of other professions such as journalism, nursing, archacology, and construction and management.
Therefore, a basic knowledge of computers helps one to be more productive and self-sufficient.
Moreover, C is considered to be the mother of all moderm-day computer languages. Almost all popular cross-platform
programming languages and scripting languages, such as C++, Java, Python, Objective-C, Perl, Ruby, PHP, Lua, and
Bash, are implemented in C and borrow syntaxes and functions heavily from C. In the programming language popularity
website, C tops the list followed by C++ and Java.
Thus, knowledge of C provides a solid foundation to learn advanced programming skills such as object-oriented
programming, event-driven programming, multi-thread programming. real-time programming, embedded programming,
network programming, parallel programming, other programming languages, and new and emerging computing
paradigms such as grid-computing and cloud computing.

ABOUT THE BOOK


This second edition of Computer Fundamentals and Programming in C has been designed as a textbook for the
undergraduate students of engineering, computer science, and computer applications. The objective of this book is to
introduce the readers to the elements of computing, computer hardware and software, and C programming.

PEDAGOGICAL FEATURES
The following are the salient features of the book:
Comprehensive coverage Provides comprehensive coverage of important topics ranging from the basics of computers
to C programming and important data structures
Case studies Includes case studies at the end of select chapters on C, which provide practical orientation to the concepts
discussed in the respective chapters.
Complete program codes Contains plenty of program codes that are thoroughly tested and compiled to support the
text
Practical orientation Provides numerous solved examples and chapter-end exercises in the form of objective-type
questions, review exercises, and programming problems that enable the students to check their understanding of the
concepts
Glossary Includes a list of key terms at the end of each chapter that facilitates revision of important topics learned
Tips and Notes Includes programming tips that educate readers about common programming errors and how to avoid
them and notes that highlight important terms and concepts in between the text as sidebars for a quick recapitulation,

NEW TO THIS EDITION


The following are the most notable additions in this:
+ Introduces a chapter on Boolean Algebra and Logic Gates, which discusses the basic concepts underlying digital
computing systems
* Many new sections have been added in this edition, The details are as follows:

Chapter 1 To provide readers a perspective of how computers evolved over the last century, this chapter presents a
section on history of computers, which gives a timeline of the developments in computing technology. The section on
applications of computers covers new applications.
it Preface to the Second Edition

3 The section on secondary storage devices includes latest devices such as Blu-ray disks and external hard
disks, The chapter now also provides section on processor architecture, which focuses on the different components of a
processor, and types of processors.
Chapter 4 This chapter includes new examples to demonstrate the addition and subtraction of hexadecimal and octal
numbers. In addition, the chapter covers codes such as Unicode and 8421 and 2421 BCD codes. The sections on logic
gates and universal gates have been moved to Chapter 5.
Chapter 5 This is a new chapter, which focuses on logic gates that form the basic building blocks of a digital circuit,
and discuses Boolean algebra, which is used to express the output of any circuit implemented using logic gates.
Chapter 6 This chapter strengthens discussion on operating systems by briefly explaining the command interpretation
module of an operating system and CLI vs GUI interface. It discusses the features of Windows 8 and Windows 10 along
with mobile operating systems, In addition, it includes a section outlining the differences between customized and public
domain software.
Chapter 7 To familiarize readers with how applications communicate over a network, this chapter provides a brief
overview of two reference models—OSI! model and TCP/IP model. In addition, it discusses Internet-related concepts
such as IP address, URL, and domain name system (DNS).
Chapter 8 \n order to make the text more coherent, this chapter has been restructured to focus on the program designing
tools that aid in the development of efficient programs. The section on programming languages has been shifted to
chapter 6.
Chapter 9 This chapter includes an annexure, which shows the steps to compile and execute C programs on both Unix/
Linux and Ubuntu platforms,
Chapter 12 This chapter adds a program showing the array representation of sparse matrices. Similarly, it includes a
program to find whether a matrix is symmetric or not.
Chapter 14 \t includes a program to illustrate the dangling pointer problem.
Chapter 15 \t presents three different ways to find the size of a structure, All these different methods have been
exemplified through program codes.

CONTENT AND COVERAGE


The book is divided into two parts spanning 18 chapters and five appendices.

Part |: Computers in Fundamentals


Chapter 1, Introduction to Computers, provides an introduction to computers. The chapter explains the generations,
classifications, applications, and the basic organization of a computer system.
Chapter 2. Input and Output Devices, presents a detailed description of the different types of input and output devices.
Chapter 3, Computer Memory and Processors, explains the significance of memory hierarchy and discusses the different
types of primary and secondary memory that are widely used to store data, It also discusses the basic processor architecture
{including RISC and CISC) and the instruction set.
Chapter 4, Number Systems and Computer Codes, discusses binary, octal, and hexadecimal number systems. The
chapter enables the reader to perform arithmetic operations on different number systems, Important codes such as ASCII,
EBCDIC, Excess 3, Gray code, and Unicode are also discussed in the chapter.
Chapter 5, Boolean Algebra and Logic Gates, introduces the concepts of digital computing systems such as Boolean
algebra, Boolean functions, Boolean expressions, and logic gates.
Chapter 6, Computer Software, provides a thorough overview of computer software. It discusses different types
of
system software and application software packages that are widely used.
Chapter 7, Computer Networks and the Internet, talks about different types of computer networks, wired and wireless
media, network devices and topologies, area networks, and data transmission mode. It also discusses the
Internet, TCP/
IP protocol, and different services provided by the Internet.
Chapter 8, Designing Efficient Programs, details the different steps in software development
process, which are
performed for creating efficient and maintai: inable programs. It also explains the different tools, which
are used to obtain
solution(s) of agiven problem at hand.
Preface to the Second Edition {& )

Part Il: Programming in C


Chapter 9, Introduction to C, discusses the building blocks of the C programming language, It includes descriptions on
identifiers, constants, variables, and operators supported by the language.
Annexure 1 shows the steps to write, compile, and execute a C program in Unix/Linux and Ubuntu environments,
Chapter 10, Decision Control and Looping Statements, deals with special types of statements such as decision control,
iterative, break, control, and jump.
Case Study 1 includes two programs which harness the concepts learnt in Chapters 9 and 10.
Chapter 11, Functions, deals with declaring, defining, and calling functions. It also discusses the storage classes as well
as variable scope in C. The chapter ends with the concept of recursion and a discussion of the Tower of Hanoi problem.
Annexure 2 discusses how to create user-defined header files,
Chapter 12, Arrays, provides a detailed explanation of arrays that includes one-dimensional, two-dimensional, and
multi-dimensional arrays, Towards the end of the chapter, the operations that can be performed on such arrays are also
explained.
Case Study 2 provides an introduction to sorting and various sorting techniques such as bubble sort, insertion sort, and
selection sort.
Chapter 13, Strings, discusses the concept of strings, which are better known as character arrays. The chapter not only
focuses on reading and writing strings but also explains various operations that can be used to manipulate them.
Chapter 14, Pointers, presents a detailed overview of pointers, pointer variables, and pointer arithmetic. The chapter also
relates the use of pointers with arrays, strings, and functions. This helps readers to understand how pointers can be used
to write better and efficient programs,
Annexure 3 explains the process of deciphering pointer declarations.
Case Study 3 includes a program which demonstrates how pointers can be used to access and manipulate strings.
Chapter 15, Structure, Union, and Enumerated Data Type, introduces user-defined data types— structures and unions.
It includes the use of structures and unions with pointers, arrays, and functions so that the inter-connectivity between the
programming techniques can be well understood.
Annexure 4 provides an explanation about bit fields and slack bytes.
Chapter 16, Files. discusses how data can be stored in files. The chapter deals with opening, processing, and closing of
files through a C program. These files are handled in text mode as well as binary mode for better clarity of the concepts,
Chapter 17, Preprocessor Directives, deals with preprocessor directives. It includes small program codes that illustrate
the use ofdifferent directives in a C program.
Chapter 18, Introduction to Data Structures, provides an introduction to different data structures such as linked lists,
stacks, queues, trees, and graphs,
Appendix A, Bitwise Operations, discusses bit-level programming and some of the bitwise operators.
Appendix B, ANS! C Library Functions, lists some of theANSI C library functions and their descriptions,
Appendix C, Advanced Type Qualifiers and Inline Functions in C, introduces some advanced type qualifiers as well as
inline functions.
Appendix D, Interview Questions with Solutions, includes about 100 frequently asked interview questions along with
their solutions.
Appendix E, Linux: A Short Guide discusses the basics of Linux kere! and shell and describes the most commonly used
Linux commands.
Appendix F, Answers to Objective Questions, provides answers to objective questions.

ACKNOWLEDGEMENTS
1 would like to gratefully acknowledge the feedback and suggestions provided by various faculty members for the
improvement of the book. | am obliged to the editorial team at Oxford University Press India for alltheir support towards
revising this book. Suggestions for improving the presentation and contents can be sent to the publishers through their
website www.india.oup.com or to me at reemathareja@ gmail.com.

Reema Thareja
Preface to the First Edition
Computers are so widely used in our day-to-day lives that imagining a life without them has become almost impossible.
They are not only used by professionals but also by children for interactively learning lessons, playing games, and doing
their homework. Applications of the computer and its users are increasing by the day.
Learning computer fundamentals is a stepping stone to having an insight into how these machines work. Once the
reader is aware of the basic terminology that is commonly used in computer science, he/she can then go on to develop
useful computer programs that may help solve a user's problems.
Since computers cannot understand human languages, special programming languages are designed for this purpose.
C is one such programming language. Being the most popular programming language, it is used in several different
software platforms such as system software and application software. A few other programming languages such as C++
and JAVA are also based on C. Hence, mastering the C language is a prerequisite for learning such languages.

ABOUT THE BOOK


Computer Fundamentals and Programming in C is aimed at serving as a textbook for undergraduate level courses in
computer science and engineering and postgraduate level courses of computer applications, The objective of this book
is to introduce the students to the fundamentals of computers and the concepts of the C programming language and
enable them to apply these concepts for solving real-world problems. The book has been designed keeping in mind the
requirements of a basic first-level course on computer fundamentals and programming, which is offered as a common
subject in all engineering disciplines. It comprehensively covers the fundamental concepts of computers, including topics
such as introduction to computers, number system, input/output devices, computer memory, computer software, the
Internet, and introduction to algorithms and programming languages. Programming is a skill best developed by rigorous
practice, Keeping this in mind, the book provides a number of examples and exercises that would help the reader learn
how to design efficient, workable programs. Various programming examples that have been thoroughly implemented and
tested have been included in the book.
To further enhance the understanding of the subject, there are numerous chapter-end exercises provided in the form of
objective type questions, review questions, and programming problems.
The book is also useful as a reference and resource to computer professionals.

ACKNOWLEDGEMENTS
The writing of this textbook was a mammoth task for which a lot of help was required from many people. Fortunately, |
have had the fine support of my family, friends, and fellow members of the teaching staff at the Institute of Information
Technology and Management, Delhi.
My special thanks would always go to my father Shri Janak Raj Thareja, my mother Smt. Usha Thareja, my brother
Pallay, and sisters Kimi and Rashi who were a source of inspiration and divine blessings for me. | am especially thankful
to my son Goransh who has been very patient and cooperative in letting me realize my dreams, My sincere thanks go to
my uncle, Mr B.L. Theraja, for his inspiration and guidance in writing this book.
Finally, | would like to acknowledge the technical assistance provided to me by Ed. Udit Chopra, who helped me in
designing and testing the numerous program codes provided in the book.
Last but not least, my acknowledgements will remain incomplete if | do not thank the editorial team at Oxford
University Press, India, for supporting me wholeheartedly during the publication of my books over the past few years.

Reema Thareja
Brief Contents
Features of the Book iv
Companion Online Resources vi
Preface to the Second Edition vii
Preface to the First Edition x
Detailed Contents xii

PART I: COMPUTER FUNDAMENTALS


1 Introduction to Computers
2 Input and Output Devices
3 Computer Memory and Processors
4 Number Systems and Computer Codes
§ Boolean Algebra and Logic Gates
6 Computer Software
7 Computer Networks and the Internet 124
8 Designing Efficient Programs 149

PART Il: PROGRAMMING IN C 163


9 Introduction to C 165
10 Decision Control and Looping Statements 205
11 Functions 248
12 Arrays 275
13 Strings 317
14 Pointers 347
15 Structure, Union, and Enumerated Data Type 386
16 Files 415
17 Preprocessor Directives 447
18 Introduction to Data Structures 460

Appendix A: Bitwise Operations 488


Appendix B: ANSI C Library Functions 490
Appendix C: Advanced Type Qualifiers and Inline Functions inC 498
Appendix D: Interview Questions with Solutions 501
Appendix E: Linux: A Short Guide 511
Appendix F: Answers to Objective Questions 516
Index 523
About the Author 525
Detailed Contents
Companion Online Resources vi
Preface to the Second Edition vii
Preface to the First Edition x
Brief Contents xi

PART I: COMPUTER FUNDAMENTALS 1


1 Introduction to Computers 3 3.12.1 CD-ROM 47
1.1 Computer 3 3.12.2 DVD-ROM 47
1,2 CharacteristicsofComputers 3 3.12.3 CD-R 47
1.3 Stored Program Concept 4 3.12.4 CD-RW 47
1.3.1 Types of Stored Program Computers 4 3.12.5 BLU-Ray Disks 48
1.4 History of Computers 5 3.13 USB Flash Drives 48
1.5 Classification of Computers 9 3.14 Memory Cards 49
1.5.1 Supercomputers 9 3.15 Mass Storage Devices 50
1.5.2 Mainframe Computers 9 3.15.1 Disk Array 50
1.5.3 Minicomputers 9 3.15.2 Automated Tape Library 50
1.5.4 Microcomputers 10 3.15.3 CD-ROM Jukebox 50
1,6 Applications of Computers // 3.16 Basic Processor Architecture 5/
1.7 Basic Organization of aComputer /5 3.16.1 Execution Unit 51
1.8 Lab Session—Inside theComputer 16 3.16.2 Registers 51
1,9 Motherboard 17 3.16.3 Bus Interface Unit 52
1.9.1 Characteristics of aMotherboard 17 3.16.4 Instruction Set 52
3.16.5 System Clock 53
2 Input and Output Devices 22
3.16.6 Processor Speed 53
2.1 Input Devices 22
3.16.7 Pipelining and Parallel
2.1.1 Keyboard 22
Processing 54
2.1.2 Pointing Devices 23
3.16.8 Types of Processors 54
2.13 Handheld Devices 25
21,4 Optical Devices 26 4 Number Systems and Computer Codes 59
2.1.5 Audiovisual Input Devices 28 4.1 Introduction to Number Systems 59
2,2 Output Devices 29 4.2 Binary Number System 59
2.2.1 Soft Copy Devices 29 4.3 Working With Binary Numbers 60
2.2.2 Hard Copy Devices 33 4.3.1 Converting a Binary Number into
Decimal Form 61
3 Computer Memory and Processors 39
4.3.2 Converting a Decimal Number into
3.1 Introduction 39
Binary Form 61
3.2 Sequential and Random Access 39
4.3.3 Adding Two Binary Numbers 61
3.3 Memory Hierarchy 39
4.3.4 Subtracting Two Binary Numbers 62
3.4 Processor Registers 40
4.3.5 Subtracting Two Binary Numbers Using
3.5 Cache Memory 40
Twos Complement 62
3.6 Primary Memory 40
4.3.6 Multiplying Two Binary Numbers 63
3.6.1 Random Access Memory (RAM) 41
4.3.7 Dividing Two Binary Numbers 63
3.6.2 Read-only Memory (ROM) 41
44 Octal Number System 63
3.6.3 Finding Required Data from Main
44.1 Converting an Octal Number into
Memory 42
Decimal Form 63
3.7 Secondary Storage Devices 42
4.4.2 Converting a Decimal Number into
3.7.1 Offline Storage 42
Octal Form 64
3.8 Magnetic Tapes 43
4.4.3 Converting an Octal Number into
3.9 Floppy Disks 43
Binary Form 64
3.10 Hard Disks 44
4.4.4 Converting a Binary Number into Octal
3.11 External Hard Disks 46
Form 64
3.12 Optical Drives 46
4.4.5 Adding Two Octal Numbers 65 5.8.2 NOR Universal Gate 86
4.4.6 Subtracting Two Octal Numbers 65 5.9 Simplification of Boolean Expressions
4.5 Hexadecimal Number System 66 Using Karnaugh Map 87
4.5.1 Converting a Hexadecimal Number into
6 Computer Software 92
Decimal Form 66
6.1 Introduction to Computer Software 92
4.5.2 Converting a Decimal Number into
6.2 Classification of Computer Software 93
Hexadecimal Form 66
6.2.1 System Software 93
4.5,3 Converting a Hexadecimal Number into
6.2.2 Application Software 96
Binary Form 67
6.3 Acquiring Computer Software 96
4.5.4 Converting a Binary Number into
6.3.1 Buying Pre-written Software 96
Hexadecimal Form 67
6.3.2 Having Customized Software 96
4.5.5 Converting a Hexadecimal Number into
6.3.3 Downloading Public Domain
Octal Form 67
4.5.6 Converting an Octal Number into
Software 97
6.4 Productivity Software 97
Hexadecimal Form 67
6.4.1 Introduction to Microsoft Office 97
4.5.7 Adding Two Hexadecimal
6.5 Graphics Software 1/09
Numbers 68
6.6 Multimedia Software 109
4.5.8 Subtracting Two Hexadecimal
6.7 Database Management Software /09
Numbers 68
6.8 Operating Systems //0
4.6 Working with Fractions 68
6.8.1 Types of Operating Systems 110
4,7 Signed Number Representation in Binary
6.8.2 Command Interpretation 111
Form 69
6.9 Popular Operating Systems //2
4.7.1 Sign-and-magnitude 70
6.9.1 Microsoft DOS 112
4.7.2 Ones Complement 70
6.9.2 Windows H3
4.7.3 Twox Complement 70
6.9.3 UNIX HS
4.8 BCD Code 70
6.9.4 Linux 116
4,9 Other Codes 71
6.10 Mobile Operating Systems 1/6
4.9.1 ASCH Code 71
6.11 Programming Languages 1/7
4.9.2 Extended Binary Coded Decimal
6.12 Generation of Programming Languages 1/8
Interchange Code 71
6.12.1 First Generation: Machine
4.9.3 Excess-3 Code 71
Language 118
4.9.4 Weighted Codes 71
6.12.2 Second Generation: Assembly
4.9.5 Gray Code 73
Language 118
4.9.6 Unicode 73
6.12.3 Third Generation; High-level
5 Boolean Algebra and Logic Gates 76 Language 119
5.1 Boolean Algebra 76 6.12.4 Fourth Generation: Very High-level
5.2 Venn Diagrams 77 Language 119
5.3 Truth Tables 77 6.12.5 Fifth Generation Programming
5.4 Basic Laws of Boolean Algebra 78 Language 120
5.4.1 Identity Law 78
7 Computer Networks and the Internet 124
5.4.2 Idempotency Law 78
7.1 Introduction to Computer Networks /24
5.4.3 Complement Law 78
7.1.1 Advantages of Computer
5.4.4 Involution Law 78
Networks 124
5.4.3 Commutative Law 78
7.2 Types of Networks 1/25
5.4.6 Associative Law 79
7.2.1 Local Area Network 125
5.4.7 Distributive Law 79
7.2.2 Wide Area Network 125
5.4.8 Absorption Law 80
7.2.3 Metropolitan Area Network 125
5.4.9 Consensus Law 80
7.2.4 Campus/Corporate Area Network 126
5.4.10 De Morgans Laws 80
7.2.5 Personal Area Network 126
5.5 RepresentationsofBoolean Functions 8/
7.2.6 Peer-to-Peer Networks 126
5.5.1 Minterm 81
7.3 Physical Components of a Network [27
5.5.2 Maxterm 82
7.4 Wired Media 127
5.6 Logic Gates 82
7.4.1 Twisted-pair Wires 127
5.7 Logic Diagrams and Boolean Expressions 84
7.4.2 Coaxial Cables 127
5.8 Universal Gates 85
5.8.1 NAND Universal Gate 85
7.4.3 Fibre Optic Cables 127
- 7.5 Wireless Media /28 7.13.1 Types of IP Addresses 139
7.5.1 Terrestrial Microwaves 128 7.14 Domain Name System 139
7.5.2 Satellite Communication 128 7.15 Uniform Resource Locator or Universal Resource
7.5.3 Infrared Communication 128 Locator [40
7.6 Networking Devices /28 7.16 Internet Services /4/
7.61 Hub 128 7.16.1 Electronic Mail 141
7.6.2 Repeater 129 7.16.2 File Transfer Protocol 142
7.6.3 Switch 129 7.16.3 Chatting 142
7.6.4 Bridge 129 7.16.4 Internet Conferencing 143
7.6.5 Router 129 7.16.5 Electronic Newspaper 143
7.6.6 Gateway 130 7.16.6 World Wide Web 143
7.6.7 Network Interface Card 130 7.16.7 Online Shopping 143
7.7 Network Topologies 130 7.16.8 Search Engine 144
7.7.1 Bus Topology 130
8 Designing Efficient Programs 149
7.7.2 Star Topology 130
8.1 Programming Paradigms /49
7.7.3 Ring Topology 131
8.1.1 Monolithic Programming 149
7.7.4 Mesh topology 131
8.1.2 Procedural Programming 149
7.7.5 Hybrid Topology 131
8.1.3 Structured Programming 150
7.8 Wireless Networks /32
8.1.4 Object-oriented Programming
7.9 Data Transmission Mode =/33
7.9.1 Simplex, Half-duplex, and Full-duplex
(OOP) 151
8.2 Example ofaStructured Program =/5/
Connections 133
8.3 Design and Implementation of Efficient
7.9.2 Serial and Parallel Transmissions 134
Programs /52
7.9.3 Synchronous and Asynchronous Data
8.4 Program Design Tools: Algorithms, Flowcharts,
Transmission Modes 135
Pseudocodes 153
7.10 Open System Interconnection
&4.1 Algorithms 153
Model 136
8.4.2 Control Structures Used in
7.11 Transmission Control Protocol/Internet
Protocol Model /38
Algorithms 153
&4.2 FLOWCHARTS $154
7.12 Internet 138
84.3 Pseudocodes 156
7.12.1 History 139
8.5 Typesof Errors 157
7.13 Internet Protocol Address /39
8.6 Testing and Debugging Approaches /58

PART Il: PROGRAMMING IN C 163


9 Introduction to C 165 9.11.1 How are Float and Double Stored? 173
9.1 Introduction 1/65 9.12 Variables 173
9.1.1 Background 165 9.12.1 Numeric Variables 173
9.1.2 Characteristics of C166 9.12.2 Character Variables 174
9.1.3 Uses of C 166 9.12.3 Declaring Variables 174
9.2 Structure ofa C Program 166 9.12.4 Initializing Variables 174
9.3 Writing the firstC Program /67 9.13 Constants 174
9.4 Files UsedinaC Program 168 9.13.1 Integer Constants 174
9.4.1 Source Code Files 168 9.13.2 Floating Point Constants 175
9.4.2 Header Files 168 9.13.3 Character Constants 175
9.4.3 Object Files 169 9.13.4 String Constants 173
9.4.4 Binary Executable Files 169 9.13.5 Declaring Constants 175
9.5 Compiling and Executing C Programs 169 9.14 InpuvOutput Statements inC 176
9.6 Using Comments 1/70 9.14.1 Streams 176
9.7 C Tokens 17/ 9.14.2 Formatting Input/Output 176
9.8 Character SetinC 171 9.14.3 printf() 176
9.9 Keywords 171 9.144 scanf() 179
9.10 Identifiers 172 9.14.5 Examples of printf/scanf 1/80
9.10.1 Rules for Forming Identifier 9.14.6 Detecting Errors During Data Input 182
Names 172 9.15 OperatorsinC 1/82
9.11 Basic Data Types inC 172 9.15.1 Arithmetic Operators 183
Detailed Contents

9.15.2 Relational Operators 184 11.9.3 extern Storage Class 260


9.15.3 Equality Operators 185 11.9.4 static Storage Class 26]
9.15.4 Logical Operators 185 11.9.5 Comparison of Storage Classes 262
9.15.5 Unary Operators 186 11.10 Recursive Functions 262
9.15.6 Conditional Operator 187 11.101 Greatest Common Divisor 263
9.15.7 Bitwise Operators 187 1110.2 Finding Exponents 264
9.15.8 Assignment Operators 189 1110.3 Fibonacci Series 264
9.15.9 Comma Operator 189 Loa} Types of Recursion 265
9.15.10 sizeof Operator 191 1111.1 Direct Recursion 265
9.15.11 Operator Precedence Chart 191 1111.2 Indirect Recursion 265
9.16 Type Conversion and Typecasting /95 11.113 Tail Recursion 265
9.16.1 Type Conversion 195 11.114 Linear and Tree Recursion 266
9.16.2 Typecasting 196 11.12 TowerofHanoi 266
Annexure 1 204 11.13 Recursion Versus Iteration 267
Annexure 2. 274
Decision Control and Looping Statements 205
10.1 Introduction to Decision Control 12 Arrays 275
Statements 205 12.1 Introduction 275
10.2 Conditional Branching Statements 205 12.2 Declaration of Arrays 275
10.2.1 Uf Statement 205 Points to Remember 276
10.2.2 if-else Statement 207 12.3 Accessing the Elements ofan Array 276
10.2.3 if-else-if Statement 209 12.3.1 Caleulating the Address of Array
10.2.4 switch case 2/2 Elements 277
10.3 Iterative Statements 2/6 12.3.2 Calculating the Length of an
10.3.1 while Loop 216 Array 277
10.3.2 do-while Loop 218 124 Storing Values in Arrays 278
10.3.3 for Loop 221 12.4.1 Initializing Arrays during
10.4 Nested Loops 224 Declaration 278
10.5 Break and Continue Statements 232 12.4.2 Inputting Values from the
10.5.1 break Statement 232 Keyboard 278
10.5.2 continue Statement 232 12.4.3 Assigning Values to Individual
10,6 goto Statement 233 Elements 278
Case Study 1: Chapters 9 and 10 245 12.5 Operations on Arrays 279
12.5.1 Traversing an Array 279
Functions 248
11.1 Introduction 248
12.5.2 Inserting an Element in an Array 283
11.1.1 Why are Functions Needed? 248 12.5.3 Deleting an Element from an
Array 286
11,2 Using Functions 249
12.5.4 Merging Two Arrays 287
11.3 Function Declaration/Function Prototype 249
12.5.5 Searching for a Value in an
11.4 Function Definition 250
11.5 Function Call 25/
Array 289
12.6 Passing Arrays to Functions 292
11.5.1 Points to Remember While Calling
12.7 Two-Dimensional Arrays 295
Functions 251
11.6 Return Statement 12.7.1 Declaring Two-dimensional
252
Arrays 295
11.6.1 Using Variable Number of
12.7.2 Initializing Two-dimensional
Arguments 253
Arrays 296
11.7 Passing Parameters to Functions 253
12.7.3 Accessing the Elements of
11.7.1 Call by Value 253
Two-dimensional Arrays 297
11.7.2 Call by Reference 254
12.8 Operations on Two-Dimensional Arrays 300
11.8 Scope of Variables 257 12.9 Passing Two-Dimensional Arrays to
11.8.1 Block Scope 257 Functions 302
11.8.2 Function Scope 258 12.9.1 Passinga Row 303
11.8.3 Program Scope 258 12.9.2 Passing an Entire 2D Array 303
11.8.4 File Scope 259 12.10 Multidimensional Arrays 305
11.9 Storage Classes 259 12.11 Sparse Matrices 306
11.9.1 auto Storage Class 259 12.111 Array Representation of Sparse
11.9.2 register Storage Class 260 Matrices 307
et Detailed Contents

12.12 Applications of Arrays 308 14,10 Difference Between Array Name and
Case Study 2: Chapter 12. 313 Pointer 360
14.11 Pointers and Strings 360
13 Strings 317 14.12 Arrays of Pointers 364
13.1 Introduction 3/7
14.13 Pointers and 2D Arrays 365
13.1.1 Reading Strings 318
14.14 Pointers and 3D Arrays 367
13.1.2 Writing Strings 319
14.15 Function Pointers 368
13.13 Summary of Functions Used to Read
14.15.1 Initializing a Function Pointer 368
and Write Characters 320
1415.2 Calling a Function Using a Function
13.2 Suppressing Input 32/
Pointer 368
13.2.1 Using a Scanset 321
14,15.3 Comparing Function Pointers 369
13.3 String Taxonomy 322
14.15.4 Passing a Function Pointeras an
13.4 Operations on Strings 322
Argument to a Function 369
13.4.1 Finding the Length of a
14.16 Array of Function Pointers 369
String 323
14.17 Pointers to Pointers 370
13.4.2 Converting Characters of a String into
14.18 Memory Allocation in C Programs 370
Upper Case 323
14.19 Memory Usage 370
13.4.3 Converting Characters of a String Into
14.20 Dynamic Memory Allocation 37/
Lower Case 324
14.20.1 Memory Allocations Process 371
13.4.4 Concatenating Two Strings to Form a
14.20.2 Allocating a Block of Memory 371
New String 324
14.20.3 Releasing the Used Space 372
13.4.5 Appending a String to Another
String 325
14.204 To Alter the Size ofAllocated
Memory 373
13.4.6 Comparing Two Strings 326
14.21 Drawbacks of Pointers 374
13.4.7 Reversing a String 325
Annexure 3 382
13.4.8 Extracting a Substring from
Left 327
Case Study 3: Chapters 13 and 14 384
13.4.9 Extracting a Substring from Right of 15 Structure, Union, and Enumerated
the String 328 Data Type 386
13.4.10 Extracting a Substring from the 15.1 Introduction 386
Middle of a String 328 15.1.1 Structure Declaration 386
13.4.11 Inserting a String in Another 15.1.2 Typedef Declarations 387
String 329 15.1.3 Initialization of Structures 388
13.4.12 Indexing 330 15.1.4 Accessing the Members ofa
13.4.13 Deleting a String from the Main Structure 388
String 330 15.1.5 Copying and Comparing
13.4.14 Replacing a Pattern with Another Structures 389
Pattern in a String 331 15.1.6 Finding the Size of a Structure 389
13.5 Miscellaneous String and Character 15.2 Nested Structures 392
Functions 33/ 15.3 Arrays of Structures 393
13.5.1 Character Manipulation 15.4 Structures and Functions 395
Functions 331 15.4.1 Passing Individual Members 395
13.5.2 String Manipulation Functions 332 15.4.2 Passing the Entire Structure 395
13.6 Arrays of Strings 337 15.4.3 Passing Structures Through
Pointers 398
M4 Pointers 347
15.5 Self-referential Structures 402
14.1 Understanding the Computer's
15.6 Unions 402
Memory 347
15.6.1 Declaring a Union 402
14.2 Introduction to Pointers 348
15.6.2 Accessing a Member of a
14.3 Declaring Pointer Variables 348
Union 403
14.4 Pointer Expressions and Pointer
15.6.3 Initializing Unions 403
Arithmetic 350
15.7 Arrays of Union Variables 404
14.5 Null Pointers 354
15.8 Unions Inside Structures 404
14.6 Generic Pointers 354
15.9 Structures Inside Unions 404
14.7 Passing Arguments to Function Using
15.10 Enumerated Data Type 405
Pointers 354
15.101 enum Variables 406
14.8 Pointers and Arrays 358
15.10.2 Using the Typedef Keyword 406
14.9 Passing an Array to a Function 359
Detailed Contents eit

15.10.3 Assigning Values to Enumerated 17.2 ‘Types ofPreprocessor Directives 447


Variables 406 17.3 #define 447
15.10.4 Enumeration Type Conversion 406 17.3.1 Object-like Macro 448
1510.5 Comparing Enumerated 17.3.2 Function-like Macros 448
Types 407 17.3.3 Nesting of Macros 449
15,10.6 Input/Output Operations on 17.3.4 Rules for Using Macros 449
Enumerated Types 407 17.3.5 Operators Related to Macros 450
Annexure 4 413 174 #include 450
17.5 #undef 451
16 Files 415
17.6 #line 451
16.1 Introduction to Files 4/5 17.7 #pragma 452
16.1.1 StreamsinC 415 17,8 Conditional Directives 454
16.1.2 Buffer Associated with File 17.81 Bifdet 454
Streams 415 17.8.2 #ifndef 454
16.1.3 Types of Files 416 17.8.3 wif 455
16.2 Using Files inC 4/7 17.84 telse 455
16.2.1 Declaring a File Pointer Variable 417 17.8.5 telif 455
16.2.2 Openinga File 417 17.8.6 tendif 456
16.2.3 Closing a File Using fclose() 418
17,9 defined Operator 456
16.3 Reading Data From Files 4/8 17,10 #error 456
16.3.1 fscanf() 418 17.11 Predefined
Macro Names 457
16.3.2 fgets() 419
16.3.3 fgetc() 420 18 Introduction to Data Structures 460
16.3.4 fread() 420 18.1 Introduction 460
16.4 Writing Data to Files 42/ 18.2 Classification of Data Structures 460
16.4.1 fprint#() 421 18.2.1 Primitive and Non-primitive Data
16.4.2 puts () 422 Structures 460
164.3 fpute () 423 18.2.2 Linear and Non-linear Structures 460
16.4.4 fwrite () 423 18.3 Arrays 461
16.5 Detecting the End-of-File 424 18.4 Linked Lists 46/
16.6 Error Handling During File Operations 424 18.4.1 Traversing a Linked List 462
16.6.1 clearerr() 425 18.4.2 Searching Linked List 462
16.6.2 perror () 425 18.4.3 Inserting a New Node in a Linked
16.7 Accepting Command Line Arguments 426 List 463
16.8 Functions for Selecting a Record 18.4.4 Deleting a Node from a Linked
Randomly 438 List 466
16.8.1 fseek() 438 18.5 Stacks 47/
16.8.2 ftell () 440 18.5.1 Operations on Stack 473
16.8.3 rewind () 440 18.6 Queues 475
16.84 fgetpos() 44/ 18.6.1 Operations on Queues 475
16.8.5 fsetpos() 441 18.7 Trees 477
16.9 Deleting a File 441 18.7.1 Representation of Binary Trees in
16.10 Renaminga File 442 Memory 478
16.11 Creating a Temporary File 442 18.7.2 Traversing a Binary Tree 478
18.8 Graphs 479
17 Preprocessor Directives 447 18.8.1 Representation of Graphs 480
17.1 Introduction 447

Appendix A: Bitwise Operations 488


Appendix B: ANSI C Library Functions 490
Appendix C: Advanced Type Qualifiers and Inline Functions in C 498
Appendix D: Interview Questions with Solutions 501
Appendix E: Linux: A Short Guide $11
Appendix F: Answers to Objective Questions 516
Index 523
About the Author 525
PART |
COMPUTER
NDAMENTALS

1 Introduction to Computers

2 Input and Output Devices

3 Computer Memory and Processors


4 Number Systems and Computer Codes

5 Boolean Algebra and Logic Gates

6 Computer Software
FA Computer Networks and the Internet

8 Designing Efficient Programs


oduction to Computers

TAKEAWAYS
* Characteristicsof computers
* Digital computers
* Stored program concept

and say that the age of the student is 23 years, then the
COMPUTER outcome is information,
These days, computers have become a crucial part of
A computer, in simple terms, can be defined as an our everyday lives, and we need computers just like we
electronic device that is designed to accept data, perform need televisions, telephones, or other electronic devices at
the required mathematical and logical operations at high home. Computers are basically meant to solve problems
speed, and output the result, quickly and accurately, The important characteristics
We all have seen computers in our homes, schools, and of a computer (refer to Figure 1.1) are discussed in the
colleges. In fact, in today’s scenario, we find computers in following text.
most aspects of our duily lives. For some of us, it is hard to
even imagine a world without them,
In the past, computers were extremely large in size
and often required an entire room for installation. These
computers consumed enormous amounts of power and
were too expensive to be used for commercial applications.
Therefore, they were used only for limited tasks, such
as computing trajectories for astronomical or military
applications, However, with technological advancements,
the size of computers became smaller and their energy
requirements reduced immensely. This opened the way for
adoption of computers for commercial purposes.
These days, computers have become so prevalent in
the market that all interactive devices such as cellular
phones, global positioning system (GPS) units, portable
organizers, automated teller machines (ATMs), and gas
pumps, work with computers.
Figure 1.1 Characteristics of computers

CHARACTERISTICS OF COMPUTERS Speed Computers can perform millions of operations per


second, which means that data that may otherwise take
We have seen that a computer is an electronic device that many hours to process is output as information in the
blink of an eye. The speed of computers is usually given
performs a function based on a given set of instructions
known as a program. A computer accepts data, processes in nanoseconds and picoseconds, where | nanosecond =
it, and produces information. Here, data refers to some
1 x 10” seconds and 1 picosecond = 1 x 10~™ seconds.
raw fact or figure, and information implies the processed Accuracy A computer is a very fast, reliable, and robust
data. For example, if 12-12-92 is the date of birth of a electronic device. It always gives accurate results,
student, then it is data (a raw fact/figure). However, when provided the correct data and set of instructions are input
we process this data (subtract it from the present-date) to it. Hence, in the event ofan error, it is the user who has
{4 Computer Fundamentals and Programming in C

id the incorrect data/program is responsible. This clearly computers also reduces manpower requirements and leads
means that the output generated by a computer depends on toan elegant and efficient way of performing various tasks.
the given instructions and input data, If the input data is Hence, computers save time, energy, and money, When
wrong, then the output will also be erroneous. In computer compared to other systems, computers can do more work
terminology, this is known as garbage-in, garbage-out in lesser time. For example, using the conventional postal
(GIGO). system to send an important document takes at least two to
three days, whereas the same information when sent using
Automation Besides being very fast and accurate, the Internet (e-mail) will be delivered instantaneously,
computers are automatable devices that can perform a
task without any user intervention. The user just needs to
assign the task to the computer, after which it automati- STORED PROGRAM CONCEPT
cally controls different devices attached to it and executes
the program instructions. All digital computers are based on the principle of stored
Diligence Unlike humans, computers never get tired of a program concept,which was introduced by Sir John von
repetitive task. It can continually work for hours without Neumann in the late 1940s. The following are the key
creating errors. Even if a large number of executions need characteristic features of this concept:
to be executed, each and every execution requires the same * Before any data is processed, instructions are read into
duration, and is executed with the same accuracy. memory.
Versatile Versatility is the quality of being flexible. Today, + Instructions are stored in the computer's memory for
execution.
computers are used in our daily life in different fields. For
* Instructions are stored in binary form (using binary
example, they are used as personal computers (PCs) for numbers—only Os and Is),
home use, for business-oriented tasks, weather forecasting,
+ Processing starts with the first instruction in the program,
space exploration, teaching, railways, banking, medicine,
which is copied into a control unit circuit. The control
and so on, indicating that computers can perform different unit executes the instructions.
tasks simultaneously. On the PC that you use at home,
you may play a game, compose and send e-mails, listen
+ Instructions written by the users are performed
sequentially until there is a break in the current flow.
to music, etc. Therefore, computers are versatile devices
as they can perform multiple tasks of different nature at * Input/Output and processing operations are performed
simultaneously, While data is being read/written, the
the same time.
central processing unit (CPU) executes another program
Memory Similar to humans, computers also have in the memory that is ready for execution,
memory. Just the way we cannot store everything in our
memory and need secondary media, such as a notebook,
to record certain important things, computers also have
internal or primary memory (storage space) as well as
external or secondary memory. While the internal memory
of computers is very expensive and limited in size, the
secondary storage is cheaper and of bigger capacity.
The computer stores a large amount of data and John W. Mauchly, an American physicist, and J.
programs in the secondary storage space. The stored Presper Eckert, an American engineer, further contributed
data and programs can be retrieved and used whenever to the stored program concept to make digital computers
required, Secondary memory is the key for data storage. much more flexible and powerful. As a result, engineers
Some examples of secondary devices include floppy disks, in England built the first stored-program computer,
optical disks (CDs and DVDs), hard disk drives (HDDs), Manchester Mark I, in the year 1949, They were shortly
and pen drives. followed by the Americans who designed EDVAC in the
When data and programs have to be used, they are very same year.
copied from the secondary memory into the internal Today, a CPU chip can handle billions of instructions
memory, often known as random access memory (RAM). per second. It executes instructions provided both the data
The concept of computer memory is discussed in detail in and instructions are valid. In case either one of them or
Chapter 3. both are not valid, the computer stops the processing of
instructions.
No 1Q Although the trend today is to make computers
intelligent by inducing artificial intelligence (AI) in them,
they still do not have any decision-making abilities of their
1.3.1 Types of Stored Program Computers
own. They need guidance to perform various tasks. A computer with a Von Neumann architecture stores data
Economical Today, computers are considered as short- and instructions in the same memory. There is a serial
term investments for achieving long-term gains. Using machine in which data and instructions are selected one
Introduction to Computers

®)

peaches address

Read/Write Data

Figure 1.2 Von Neumann architecture (a) Shared memory for instructions and data (b) Separate
memories for instructions and data

at a time. Data and instructions are transferred to and China. It was used by the Babylonians even in 300 BC and
from memory through a shared data bus. Since there is a is still in use today (in the Far East).
single bus to carry data and instructions, process execution
1822: English mathematician Charles Babbage designed
becomes slower.
a steam-driven calculating machine that could compute
Later Harvard University proposed a stored program
tables of numbers. Though the project failed as he could
concept in which there was a separate memory to store
not complete the construction of the engine, it laid the
data and instructions, Instructions are selected serially
foundation for the first computer.
from the instruction memory and executed in the processor.
When an instruction needs data, it is selected from the data 1890: Herman Hollerith, an American inventor, designed
memory, Since there are separate memories, execution a punched card system to calculate the 1880 census,
becomes faster, The system completed the task in three years saving the
US government $5 million. Later Herman established a
company that we today know as IBM.
HISTORY OF COMPUTERS 1936: British mathematician Alan Turing introduced
4 universal machine called the Turing machine capable
Early computers were designed not for entertainment but of computing anything that is computuble, The central
for solving number-crunching problems. These computers concept of the modern computer is based on this machine.
were punch-card based computers that took up entire rooms,
1941: John Vincent Atanasoff, a Bulgarian-American
‘Today, our smurtphones have much more computing power
physicist, and his graduate student, Clifford Berry, at lowa
than that was available in those early computers,
State College designed Atanasoff—Berry computer (ABC)
In this section, we will read about history ofcomputers
that could solve 29 equations simultaneously. It was the
way back from the invention of abacus and take a look at
first time a computer could store information in its main
the remarkable achievements in computing technology till
memory.
the current time,
1943-1944: John W. Mauchly and J. Presper Eckert
Timeline of Developments built the Electronic Numerical Integrator and Calculator
(ENIAC), which is considered as the grandfather of digital
300 BC: The abacus was an early aid for mathematical computers. It filled a 20 x 40 feet room and had 18,000
computations and was designed to aid human’s memory vacuum tubes.
while performing calculations. A skilled abacus operator
can add and subtract with the same speed asthat ofa person 1946: Mauchly and Presper designed the UNIVAC,
performing the same calculation using a hand calculator. which was the first commercial computer for business and
The invention of abacus is often wrongly attributed to government applications.
86 Computer Fundamentals and Programming in C

: William Shockley, John Bardeen, and Walter 1986: Compaq introduced Deskpro 386 in the market,
Brattain of Bell Laboratories invented the transistor. Soon which was a 32-bit architecture machine that provides
vacuum tubes in computers were replaced by transistors. speed comparable to mainframes.
1953: Grace Hopper developed the first computer 1990: Tim Berners-Lee invented World Wide Web with
language COBOL. HTML as its publishing language.
1954: The FORTRAN programming language was 1993: The Pentium microprocessor introduced the use of
developed. graphics and music on PCs.
1958: Jack Kilby of Texas Instruments and Robert 1994: PC games became popular.
Noyce at Fairchild Semiconductor Corporation separately
1996: Sergey Brin and Larry Page developed the Google
invented integrated circuit, which is commonly known as search engine at Stanford University.
the computer chip.
1999: The term Wi-Fi was introduced when users started
1964: Douglas Engelbart developed a prototype of the
connecting to the Internet without wires.
modern computer, with a mouse and a graphical user
interface (GUI). This was a remarkable achievement 2001: Apple introduced Mac OS X operating system,
as it shifted computers from a specialized machine for which had protected memory architecture and pre-emptive
scientists and mathematicians to general public. multi-tasking, among other benefits, To stay competitive,
1969: Unix operating system was developed at Bell Labs. Microsoft launched Windows XP.
It was written in the C programming language and was 2003: The first 64-bit processor, AMD's Athlon 64, was
designed to be portable across multiple platforms, Soon it brought into the consumer market,
became the operating system of choice among mainframes
at large companies and government entities. 2004: Mozilla released Firefox 1.0 and in the same year
Facebook, a social networking site, was launched.
1970: DRAM chip was introduced by Intel.
2005: YouTube, a video sharing service, was launched. In
1971: Alan Shugart with his team in IBM invented the same year, Google acquired Android, a Linux-based
the floppy disk which allowed data to be shared among mobile phone operating system.
computers.
2006: Apple introduced MacBook Pro, its first Intel-
1973: Robert Metcalfe, a research member at Xerox, based, dual-core mobile computer.
developed Ethernet for connecting multiple computers
and other hardware. 2007: Apple released iPhone, which brought many
computer functions in the smartphone.
1974-1977: Personal computers started =becoming
popular, 2009: Microsoft launched Windows 7 in which users
1975: Paul Allen and Bill Gates started writing software for could pin applications to the taskbar.
the Altair 8800 using the new BASIC language. On Apnil 4. 2010: Apple launched iPad, which revived the tablet
they both formed their own software company, Microsoft. computer segment.
1976: Steve Jobs and Steve Wozniak started Apple 2011: Google introduced Chromebook, a laptop that runs
Computers and developed Apple I, the first computer with on the Google Chrome operating system.
a single-circuit board.
2015: Apple released the Apple Watch. In the same year,
1977: Apple Il was launched that offered colour graphics Microsoft launched Windows 10.
and incorporated an audio cassette drive for storage.
After reading these interesting developments in
1978: WordStar, a word processor application, was computing technology, let us also understand the evolution
released by MicroPro International. of computers through different generations.
1979: VisiCalc. the first computerized spreadsheet
program for personal computers, was unveiled. First Generation (1942-1955)
1981: The first IBM personal computer was introduced Hardware Technology First generation computers were
that used Microsoft's MS-DOS operating system. The manufactured using thousands of vacuum tubes (see
term PC was popularized. Figure 1.3); a vacuum tube is a device made of fragile glass.
1983: The first laptop was introduced. Moreover, Apple Memory Electromagnetic relay was used as primary
introduced Lisa as the first personal computer with a GUI memory and punched cards were used to store data and
with drop-down menus and icons. instructions.
1985: Microsoft announced Windows as a new operating Software Programming was done in machine
system, or assembly language.
Introduction to Computers Cc

Used for Scientific applications * They consumed 1/10th the power consumed by
generation computers
Examples ENIAC, EDVAC, EDSAC, UNIVAC 1, IBM 701 * Bulky in size and required a complete room for its
Highlights installation
* They were the fastest calculating device of those times + Dissipated less heat than first generation computers but
still required air-conditioned rooms
* Computers were too bulky and required a complete
* Costly
room for storage
* Highly unreliable as vacuum tubes emitted a large * Difficult to use
amount of heat and burnt frequently
Required air-conditioned rooms for installation
Costly
Difficult to use
Required constant’ maintenance because vacuum
tubes used filaments that had limited life time. até
Therefore, these computers were prone to frequent
hardware failures
o*

Figure 1.4 Transistors


Source: yurazaga/Shutterstock

Third Generation (1964-1975)


Hardware Technology Third generation computers were
manufactured using integrated chips (ICs) (shown in
Figure 1.5). ICs consist of several components such as
transistors, capacitors, and resistors on a single chip to
avoid wired interconnections between components, These
computers used S$/ and MSI technology. Minicomputers
came into existence,
Figure 1.3 Vacuum tube
Source: Viadyslav Danilin/Shutterstock
Initially, (Cs contained 10-20 components,This
technology was called Small ScaleIntegration (SSi). Later,
Second Generation (1955-1964) was enhanced tocontain about 100 components. This
Hardware Technology Sccond generation computers was called MSI (Medium Scale integration),
were manufactured using transistors (see Figure 1.4).
Transistors were reliable, powerful, cheaper, smaller, and Memory Larger magnetic core memory was used as
cooler than vacuum tubes. primary memory; larger capacity magnetic tapes and
magnetic disks were used to store data and instructions.
Memory Magnetic core memory was used as primary
memory; magnetic tapes and magnetic disks were used Software Technology Programming was done in high level
to store data and instructions. These computers had faster programming languages such as FORTRAN, COBOL,
and larger memory than the first generation computers. Pascal, and BASIC. Time sharing operating system was
used. Software was separated from the hardware. This
Software Technology Programming was done in high allowed users to invest only in the software they need.
level programming languages. Batch operating system
was used. Used for Scientific, commercial, and interactive online
applications
Used for Scientific and commercial applications
Examples 1BM 360/370, PDP-8, PADP-11, CDC6600
Examples Honeywell 400, IBM 7030, CDC 1604,
UNIVAC LARC Highlights
* Faster, smaller, cheaper, reliable, and easier to use than
Highlights the second generation computers
* Faster, smaller, cheaper, reliable, and easier to use than * They consumed less power than second generation
the first generation computers computers
8 Computer Fundamentals and Programming in C

Bulky in size and required a complete room for Highlights Faster, smaller, cheaper, powerful, reliable,
installation and easier to use than the previous generation computers
* Dissipated less heat than second generation computers
but still required air-conditioned rooms
* Costly
* Easier to use and upgrade

Figure 1.5 Integrated circuits Figure 1.6 VLSI chip


Source: cooldesign/FreeDigitalPhotos. net
Fifth Generation (1989-Present)
Fourth Generation (1975-1989) are
Hardware Technology Fifth generation compute:
Hardware Technology Fourth generation computers manufactured using ICs with ULSI (Ulta Large Scale
were manufactured using ICs with LSI (Large Scale Integrated) technology. The use of Internet became
Integrated) and later with VLSI technology (Very Large widespread and very powerful mainframes, desktops,
Scule Integration), Microcomputers came into existence. portable laptops, and smartphones are being used commonly
Use of personal computers became widespread. High Supercomputers use parallel processing techniques,
speed computer networks in the form of LANs, WANs,
and MANs started growing, Besides mainframes,
supercomputers were also used ULSI circuits contain about 10 million electronic
componen ts
on a single chip.

ts
on asingle
LSI circuits contained 30,000 componen chip
Memory Semiconductor memory is used as primary
and VLSI technology had about one million electronic memory: large capacity magnetic disks are used as built-in
componen ts
on asingle chip. secondary memory. Magnetic tapes and floppy disks were
used as portable storage devices, which have now been
Memory Semiconductor memory was used as primary replaced by optical disks and USB flash drives.
memory, large capacity magnetic disks were used as built-
Software Technology Programming is done in high-level
in secondary memory. Magnetic tapes and floppy disks
programming languages such as Java, Python, and C#
were used as portable storage devices Graphical User Interface (GUI)-based operating systems
Software Technology Programming was done in such as Windows, Unix, Linux, Ubuntu, and Apple Mac
high level programming language such as C and C++ are being used. These operating systems are more powerful
Graphical User Interface (GUI) based operating system and user friendly than the ones available in the previous
(c.g. Windows) was introduced. It had icons and menus generations.
among other features to allow computers to be used as Used for Scientific, commercial, interactive online,
a general purpose machine by all users. UNIX was also
multimedia (graphics, audio, video), and network applications
introduced as an open source operating system. Apple Mac
OS and MS DOS were also released during this period. All Examples 1BM_ notebooks, Pentium PCs, SUM
these operating systems had multi-processing and multi- workstations, IBM SP/2, Param supercomputer
programming capabilities, Highlights
Used for Scientific, commercial. interactive online, and * Faster, smaller, cheaper, powerful, reliable, and easier to
network applications use than the previous generation computers
Examples 1BM PC. Apple Il, TRS-80, VAX 9000, CRAY- * Speed of microprocessors and the size of memory are
1, CRAY-2, CRAY-X/MP growing rapidly
Introduction to Computers
ce
(0 )

* High-end features available on mainframe computers units, etc. Some examples of supercomputers are CRAY=Ty
in the fourth generation are now available on the CRAY-2, Control Data CYBER 205, and ETA A-10,
mucroprocessors

* They consume less power than computers of prior 1.5.2 Mainframe Computers
generations
* Air-conditioned rooms required for mainframes and Mainframe computers are large-scale computers (but
supercomputers but not for microprocessors smaller than supercomputers). These are very expensive and
need a very large clean room with air conditioning, thereby
making them very costly to deploy. As with supercomputers,
mainframes can also support multiple processors. For
example, the IBM $/390 mainframe can support 50,000
users at the same time. Users can access mainframes by
cither using terminals or via PCs. The two types of terminals
that can be used with mainframe systems are as follows:

Dumb Terminals
Dumb terminals consist of only a monitor and a keyboard
(or mouse). They do not have their own CPU and memory
Figure 1.7 ULSI chip and use the mainframe system's CPU and storage devices.

Intelligent Terminals
CLASSIFICATION OF COMPUTERS
In contrast to dumb terminals, intelligent terminals have
Computers can be broadly classified into four categories their own processor and thus can perform some processing
based on their speed, amount of data that they can process, operations. However, just like the dumb terminals, they do
and price (refer to Figure 1.8). These categories are as not have their own storage space. Usually, PCs are used
follows: as intelligent terminals to facilitate data access and other
+ Supercomputers services from the mainframe system.
+ Mainframe computers Mainframe computers are typically used as servers on
+ Minicomputers the World Wide Web. They are also used in organizations
* Microcomputers such as banks, airline companies, and universities. where
a large number of users frequently access the data stored
1.5.1 Supercomputers in their databases, IBM is the major manufacturer of
mainframe computers. Some examples of mainframe
Among the four categories, the supercomputer is the computers include IBM $/390, Control Data CYBER 176,
fastest, most powerful, and most expensive computer. and Amdah! 580.
Supercomputers were first developed in the 1980s to
process large amounts of data and to solve complex 1.5.3 Minicomputers
scientific problems, Supercomputers use parallel
processing technology and can perform more than one As the name suggests, minicomputers are smaller,
trillion calculations in a second. cheaper, and slower than mainframes. They are called
A single supercomputer can support thousands of users at minicomputers because they were the smallest computer
the same time, Such computers are mainly used for weather of their times. Also known as midrange computers, the
forecasting, nuclear energy research, aircraft design, capabilities of minicomputers fall between mainframe and
automotive design, online banking, controlling industrial personal computers.

Classification
of computers

Supercomputers Mainframe computers Minicomputers Microcomputers

Dumb terminals Intelligent terminals Desktop PCs Laptops Handheld devices

Workstations Network computers

Figure 1.8 Classification of computers


fi
10 Computer Fundamentals and Programming in C

are widely used in business, education, easily be carried from one place to another. They may also
hospitals, government organizations, ctc. While some be placed on the user's lap (thus the name). Hence, laptops
minicomputers can be used only by a single user, others are very useful, especially when going on long journeys.
are specifically designed to handle multiple users Laptops operate on a battery and do not always have to be
simultancously, Usually, single-user minicomputers are plugged in like desktop computers.
used for performing complex design tasks. ‘The memory and storage capacity of a laptop is almost
As with mainframes, minicomputers can also be used equivalent to that of a desktop computer. As with desktop
as servers in a networked environment, and hundreds of computers, laptops also have hard disk drives, USB drives,
PCs can be connected to it, etc, For input, laptops have a built-in keyboard and a
The first minicomputer was introduced by Digital trackball/touchpad, which is used as a pointing device (as
Equipment Corporation (DEC) in the mid-1960s, Other a mouse is used for a desktop PC).
manufacturers of minicomputers include IBM Corporation Today, laptops have the same features and processing
(AS/400 computers), Data General Corporation, and speed as the most powerful PCs. However, a drawback is
Prime Computer. that laptops are generally more expensive than desktop
computers. These computers are very popular among
1.5.4 Microcomputers business travellers.

Microcomputers, commonly known as PCs, are very small Workstations


and cheap. The first microcomputer was designed by IBM
in 1981 and was named IBM-PC, Later on,many computer Workstations are single-user computers that have the same
hardware companies copied this design and termed their features as PCs, but their processing speed matches that
microcomputers as PC-compatible, which refers to any of a minicomputer or mainframe computer. Workstation
PC that is based on the original IBM PC design. computers have advanced processors, more RAM and
Another type of popular PC is designed by Apple. PCs storage capacity than PCs. Therefore. they are more
designed by IBM and other PC-compatible computers expensive and powerful than a normal desktop computer.
have a different architecture from that of Apple computers. Although workstation computers are widely used as
Moreover, PCs and PC-compatible computers commonly powerful single-user computers by scientists, engineers,
use the Windows operating system, while Apple computers architects, and graphic designers, they can also be used as
use the Macintosh operating system (MacOS). PCs can be servers in a networked environment,
classified into the following categories:
Network Computers
Desktop PCs
Network computers have less processing power,
A desktop PC is the most popular model of PCs. The memory, and storage than a desktop computer. These are
system unit of the desktop PC can be placed flat on a desk specially designed to be used as terminals in a networked
or table. It is widely used in homes and offices. environment. For example, some network computers are
specifically designed to access data stored on a network
Laptops (including the Intemet and intranet).
Some network computers do not have any storage space
Laptops (Figure 1.9) are small microcomputers that can and merely rely on the network’s server for data storage and
eusily fit inside a briefcase. They are very handy and can processing tasks. The concept of network computers had
become popular in the mid-1990s when several variations
of computers such as Windows terminals, NetPCs, and
diskless workstations were widely used.
Network computers thatare specifically designed to access
only the Internet or intranet are often known as Internet PCs
or Intemet boxes. Some network computers used in homes do
not even have a monitor. Such computers may be connected
to a television, which serves as the output device, The most
common example of a home-based network computer is
Web TV, which enables the user to connect a television to the
Internet. The Web TV is equipped with a special set-top box
that is used to connect to the Internet. The set-top box also
provides controls to enable the user to navigate the Internet,
send and receive e-mails, and to perform other tasks on the
network while watching television. The other reason for the
Figure 1.9 Laptop popularity of network computers is that they are cheaperto
Source: You can more/Shutterstock purchase and maintain than PCs.
Introduction to Computers {or i

Handheld Computers + Watching movies


+ Playing games
The mid-1990s witnessed a range of small personal * Sharing pictures, video, songs, documents, etc.
computing devices that are commonly known as handheld * Browsing the Internet
computers, or mobile computers. These computers are * Keeping in touch with friends and family on popular
called handheld computers because they can fit in one social networks, sending emails
hand, while users can use the other hand to operate them. * Business people use them to perform tasks such as
Handheld computers are very small in size, and hence they editing a document, exchanging documents, taking
have small-sized screens and keyboards. These computers notes, and giving presentations
are preferred by business travellers and mobile employees + Tablets are best used in crowded places such as airports
whose jobs require them to move from place to place. and coffee shops, where size and portability become
Some examples of handheld computers are as follows: more important.
* Smartphones
* Tablet PCs
Smartphones Thescdays,cellularphones are web-enabled ‘Tablets may replace laptops ifusers don’t have to
telephones. Such phones are also known as smartphones perform heavy processing tasks and do not require a CD
because, in addition to basic phone capabilities, they also or DVD player
facilitate the users to access the Intemet and send e-mails,
edit Word documents, generate an Excel sheet, create a
presentation, and lots more,
Smartphones run an advanced mobile operating
system that enables it to run various applications, The
four major mobile operating systems are iOS, Android,
BlackBerryOS, and Windows Mobile. Smartphones also
have a CPU, more storage space, more memory, and 4
larger screen than a regular cell phone.
In & nutshell, smartphone refers to a multi-functional
mobile phone handset that packs in varied functionalities
from a camera to a web browser to a high-density display.
Tablet PCs A tablet PC (sce Figure 1.10) is a computing
device that is smaller than a laptop, but bigger than a
smartphone. Features such as user-friendly interface,
Figure 1.10 Tablet
portability, and touch screen huve made them very
popular in the last few years. These days, a wide range Source: bloomua/Shutterstock/OUP Picture Bank
of high-performance tablets are available in the market.
While all of them look similar from outside, they may RD Appuications OF COMPUTERS
differ in features such as operating system, speed of data
connectivity, camera specifications, size of the screen, When the first computers were developed, they were used
processing power, battery life, and storage capability. only in the fields of mathematics and science, In fact, the
Some operating systems that are used in tablets are first effective utilization of computers was for decoding
Android Jellybean (an open-source operating system messages in military applications. Later on, computers
built by Google), Windows 8, and iOS (developed by were used in real-time control systems, like for landing on
Apple), Each operating system has its own advantages the moon. However, with the advancement of technology,
and disadvantages and a proprietary app store, from which the cost of computers and their maintenance declined.
users can download applications, extending the tablet’s This opened the way for computers to be extensively used
functionality, These apps range from games to specialized in the business and commercial sector for information
word processors and even instruments. processing. Today, computers are widely used in fields
While users can easily type directly on the surface of a such as engineering, health care, banking, education,
tablet, some users prefer a wireless or bluctooth-connected etc, Let us discuss how computers are being effectively
keyboard. These days, tablets also offer an optional utilized to perform important tasks.
docking station with keyboards that transforms the tablet
Word processing Word processing software enables users
into a full-featured netbook.
to read and write documents. Users can also add images,
Uses The following are the uses of Tablet PCs: tables, and graphs for illustrating a concept. The software
+ View presentations automatically corrects spelling mistakes and includes
« Videoconferencing copy-paste features (which is very useful where the same
* Reading e-books, e-newspaper text has to be repeated several times).
i12 Computer Fundamentals and Programming in C

The Intemet is a network of networks that stocks, finding a job, conducting an auction, marketing
connects computers all over the world. It gives the user and advertising products or services, and providing
access (0 an enormous amount of information, much more customer service. The following are techniques in which
than available in any library. Using e-mail, the user can e-commerce helps users to conduct business transactions.
communicate in seconds with a person who is located Business-to-consumer or B2C In this form of electronic
thousands of miles away. Chat software enables users commerce, business companies deploy their websites
to chat with another person in real-time (irrespective of on the Internet to sell their products and services to the
the physical location of that person), Video conferencing customers. On their websites, they provide features such
tools are becoming popular for conducting mectings with as cutalogues, interactive order processing system, secure
people who are unable to be present at a particular place. electronic payment system, and online customer support.
Digital video or audio composition Computers make
Business-to-business or B2B This type of electronic
audio or video composition and editing very simple. This
commerce involves business transactions performed
has drastically reduced the cost of equipment to compose between business partners (customers are not involved).
music or make a film. Graphics engineers use computers For example, companies use computers and networks (in
for developing short or full-length films and creating 3-D
the form of extranets) to order raw materials from their
models and special effects in science fiction and action
suppliers. Companies can also use extranets to supply
movies,
their products to their dealers.
Desktop publishing Desktop publishing software enables
Consumer-to-consumer or C2C This type of electronic
us to create page layouts for entire books.
commerce enables customers to carry business transactions
After discussing how computers are used in today’s among themselves. For example, on auction websites,
scenario, let us now have a look at the different areas a customer sells his/her product which is purchased by
where computers are being widely utilized. another customer.

e-Business Electronic banking Electronic banking, also known as


cyberbanking or online banking, supports various banking
e-Business or electronic business is the process of activities conducted from home, a business, or on the road
conducting business via the Internet. This may include instead of a physical bank location,
buying and selling of goods and services using computers
and the Internet, Use of email and videoconferencing Bioinformatics
technology has revolutionized the way business is being
conducted these days, Bioinformatics is the application of computer technology
While an e-mail is a service that delivers messages fo manage large amount of biological information.
from a sender to One or more receivers via computer, Computers are used to collect, store, analyse, and integrate
voice mail systems capture, store, and transmit spoken biological and genetic information to facilitate gene-based
messages. Videoconferencing, which is an advanced form drug discovery and development, The need for analysis has
of teleconferencing, provides a complete simulation of become even more important with enormous amount of
a normal meeting environment in which all concerned genomic information available publicly from the Human
parties can sec, heur, and present material, just as if they Genome Project.
were in the same room, These meetings not only speed up Bioinformatics is an interdisciplinary field of molecular
business process but also save the cost of travel and cost of biology, computer science, statistics, and mathematics. It
the time wasted during travel. involves analyses of genomic information to understand
human diseases and thus discover new drugs to treat those

We know that DNA is made up of smaller picces of


molecules and the sequence of molecules along a string
of DNA contains all information about an organism, This
information can be used to grow new organisms. For
Companies today use ¢-commerce applications for example, scientists are using this information to grow
marketing, tansaction, processing, and product and better variety of crops, to generate a genome that will
customer services processing. For example, the website enable cows to yield more milk, so and so forth.
of a company can perform activities such as interactive Therefore. bioinformatics helps scientists to store the
marketing, ordering, payment, and customer support DNA information in huge databases, retrieve it as and
process. when required, and analyse it to grow and develop new
e-commerce used to perform transactions between
business partners or customers has several applications Scientists also use bioinformatics to identify diseases
such as home banking. electronic shopping, buying and discover drugs for them. This is done by writing
Introduction to Computers (13

special programs that compare the sequence of molecules Doctors sitting in hospitals can monitor their t
in DNA of a healthy person with that ofthe patient's. These sitting in their homes by using computer-based systems.
analyses help them to identify what is missing in a patient As soon as warning signs of serious illnesses are spotted,
and to determine drugs that can make the molecules in they alert the concerned doctor quickly.
DNA of the patient look similar to that of a healthy person.
For example, one of the drugs to treat AIDS was designed Geographic Information System and
using bioinformatics techniques.
Remote Sensing
Health care A geographic information system (GIS) is a computer-
based tool for mapping and analysing earth’s features.
Last few years have seen a massive growth of computers
It integrates database operations and statistical
and smartphone users. Like in our daily lives, computers
analysis to be used with maps. GIS manages location-
have also become 4 necessary device in the health care
based information and provides tools for display and
industry, The following are areas in which computers are
analysis of statistics such as population count, types of
extensively used in the health care industry.
vegetation, and economic development opportunities.
Storing records To begin with, computers are first and Such type of information helps to predict outcomes and
foremost used to store the medical records of patients. plan strategies.
Earlier, patient records were kept on paper, with separate Remote sensing is the science of taking measurements
records dealing with different medical issues from separate of the earth using sensors. on airplanes or satellites. These
healthcare organizations. With time, the number of sensors collect data in the form of images, which are then
prescriptions, medical reports, etc., grow in volume making analysed to derive useful information.
it difficult to maintain and analyse. Use of computers to The key feature of remote sensing is that it acquires
store patient records has been a game-changer in terms of information about an object without making physical
improving the efficiency and accuracy of the entire process. contact with it, Remote sensing is a sub-field of geography,
Now, the entire medical history of patients is easily which can be applied in the following areas to collect data
accessible, Since the records are electronically stored, they of dangerous or inaccessible areas for the following:
can be easily shared between different doctors (in same
* Monitoring deforestation in areas like the Amazon
or different healthcare organizations) who are treating
Basin
the same patient. Besides saving paper and enhancing * Studying features of glaciers in Arctic and Antarctic
efficiency, use of computers also saves patients’ money by regions
reducing duplication of tests and procedures.
Analysing the depth of coastal and ocean areas
Surgical procedures Computers are used for certain Studying land usage in agriculture
surgical procedures. They enable the surgeon to use Examining the health of indigenous plants and crops
computer to control and move surgical instruments in Determining the prospect for minerals
the patient's body for a variety of surgical procedures. In CUS
ewLocating and measuring intensity of earthquakes (after
such surgeries, a small incision is made, and then a small they had occurred) by comparing the relative intensity
surgical tool with an attached camera is placed inside the and precise timings of seismograms collected from
patient's body. This reduces the riskofcomplications from different locations
a larger surgical wound, and minimizes damage done to
the patient's body. In such a scenario, computers are not Meteorology
only used to drive the tools but also used to relay images
from inside the patient's body out to the doctors. Metcorology is the study of the atmosphere, This branch of
Computers also help to determine the cause of an science observes variables of Earth’s atmosphere such as
affliction or illness. For example, computers can combine temperature, air pressure, water vapour, and the gradients
ultrasonography and imaging in fields like cardiology to and interactions of each variable, and how they change
check the functionality of the heart. In case of a serious over time, Meteorology has applications in many diverse
ailment, the causes can be detected in less time and fields such as the military, energy production, transport,
treatment can be started at the earliest thereby saving a agriculture, and construction. Some of the applications
numberof lives. include the following:
Today, tablets and computers are being used in surgical Weather forecasting It includes application of science
consultations and videoconferencing between doctors. and technology to predict the state of the atmosphere
Better diagnosis and treatment Computers help (temperature, precipitation, etc.) for a future time and a
physicians make better diagnoses and recommend given location, Weather forecasting is done by collecting
treatments. Moreover, computers can be used to compare quantitative data about the current state of the atmosphere
expected results with actual results in order to help and analysing the atmospheric processes to project how
physicians make better decisions. the atmosphere will evolve.
{4 Computer Fundamentals and Programming in C

forecasts are especially made to generate explanation. However, they find it interesting to learn
warnings regarding heavy rainfall, snowfall, etc. They are through interacting with an animation of the algorithm
also important to agriculturists and also to commodity
traders within stock markets, Temperature forecasts
are used by utility companies to estimate demand over
coming days. Edutainment
isthecombination ofeducation with
entertainment.
Aviation meteorology Aviation meteorology studies the
impact of weather on air traffic management. It helps Legal System
cabin crews to understand the implications of weather on
their flight plan as well as their aircraft, Computers are used by lawyers to shorten the time required
to conduct legal precedent and case research. Lawyers use
Agricultural meteorology Agricultural meteorology computers to look through millions of individual cases and
deals with the study of effects of weather and climate on tind whether similar or parallel cases have been approved,
plant distribution, crop yield, water-use efficiency, plant denied, criticized, or overruled in the past. This enables
and animal development. the lawyers to formulate strategies based on past case
Nuclear meteorology Nuclear meteorology studies decisions. Moreover. computers are also used to keep
the distribution of radioactive aerosols and gases in the track of appointments and prepare legal documents and
atmosphere. briefs in time for filling cases,

Maritime meteorology Maritime meteorology is the Retail Business


study of air and wave forecusts for ships operating al sea,
Computers are used in retail shops to enter orders, calculate
Multimedia and Animation costs, and print receipts. They are also used to keep an
inventory of the products available and their complete
Multimedia and animation that combines still images, description,
moving images, text, and sound in meaningful ways is
one of most powerful aspects of computer technology. We Sports
all have seen cartoon movies, which are nothing but an
example of computer animation. In sports, computers are used to compile statistics,
identify weak players and strong players by analysing
N ote
statistics, sell tickets, create training programs and diets
for athletes, and suggest game plan strategies based on
Displaying a number ofstillimages within afraction ofa the competitor's past performance. Computers are also
used to generate most of the graphic art displays flashed
atleast 30stillimages ina second gives
aneffect ofa on scoreboards.
Television networks use computers in the control room
to display action replays and insert commercial breaks as
Using animation software, we can reproduce real- per schedule.
world phenomena such as fire, smoke, fluids, movement of In addition, there are simulation software packages
chemicals through the air and ground. and the respiratory available that help a sportsperson to practice his or her
system to name a few, Animation is an easy and effective skills as well as identify flaws in the technique,
way to show complex interactions or events. Thus, it is an
excellent tool for educating an audience. Travel and Tourism
A dynamic multimedia presentation (created using Computers are used to prepare tickets, monitor the train's
tools like MS PowerPoint) can make the message not or airplane's route, and guide the plane to a safe landing.
only easily understood but also effective. Multimedia ‘They are ulso used to research about hotels in an area,
presentation helps corporate people to share information reserve rooms, Or to rent a car.
or their ideas and graphically present information in a
more understandable and persuasive manner. Multimedia Simulation
presentations can be recorded and played or displayed
dynamically depending on user's inputs. Multimedia and Supercomputers that can process enormous amount of
animation is used to create computer games. A laser show data are widely used in simulation tests. Simulation of
is also an example of a multimedia application, automobile crashes or airplane emergency landings is done
Multimedia and animation is used to add special effects to identify potential weaknesses in designs without risking
in movies. In education, multimedia is used to prepare human lives. Supercomputers also enable engineers to
training courses, Students find learning complex computer design aircraft models and simulate the effects that winds
algorithms and data structures by reading only a textual and other environmental forces have on those designs.
Introduction to Computers ce

Astronauts are trained using computer-simulated problems humans cannot work, For example, in high t
that could be encountered during launch, in space, or upon high pressure conditions or in processes that demand very
return to earth. high levels of accuracy. The main distinguishing feature
between a robot and other automated machines is that @
Astronomy robot can be programmed to carry out a complex task and
then reprogrammed to carry out another complex tasks.
Spacecrafts are usually monitored using computers that
not only keep a continuous record of the voyage and Decision Support Systems
of the speed, direction, fuel, and temperature, but also
suggest corrective action if the vehicle makes a mistake. Computers help managers to analyse their organization's
The remote stations on the carth compare all these data to understand the present scenario of their business,
quantities with the desired values, and in case these values view the trends in the market, and predict the future of their
need to be modified to enhance the performance of the products. Managers also use decision support systems to
spacecraft, signals are immediately sent that set in motion analyse market research data, to size up the competition,
the mechanics to rectify the situation. With the help of and to plan effective strategies for penetrating their
computers, all this is done within a fraction of a second. markets.

Education Expert Systems

A computer is a powerful teaching aid and can act as Expert systems are used to automate the decision-making
another teacher in theclassroom, Teachers use computers to process in a specific area, such as analysing the credit
develop instructional material. Teachers may use pictures, histories for loan approval and diagnosing a patient's
graphs, and graphical presentations to casily illustrate condition for prescribing an appropriate treatment. Expert
an otherwise difficult concept. Moreover, teachers at all systems analyse the available data in depth to recommend
levels can use computers to administer assignments and a course of action. A medical expert system might provide
keep track of grades. Students can also give exams online
the most likely diagnosis of patient's condition.
and get instant results. To create an expert system, an extensive amount of
human expertise in a specific area is collected and stored
in a database, also known as a knowledge base. A software
Industry and Engineering
called an interface engine analyses the data available
Computers are found in all kinds of industries, such in the knowledge base and selects the most appropriate
as thermal power plants, oil refineries, and chemical response.
industries, for process control, computer-aided designing Adding more to it, in today’s scenario, computers are
(CAD), and computer-aided manufacturing (CAM). used to find jobs on the Internet, read news and articles
Computerized process control (with or without human online, find your batchmates, send and receive greetings
intervention) is used to enhance efficiency in applications pertaining to different occasions, etc.
such as production of various chemical products, oil
refining, paper manufacture, and rolling and cutting steel
to customer requirements. BASIC ORGANIZATION OF
In CAD, computers and graphics-oriented software are
integrated for automating the design and drafting process.
A COMPUTER
It helps an engincer to design a 3D machine part, analyse
A computer is an electronic device that performs five
its characteristics, and then subject it to simulated stresses. major operations:
In case a part fails the stress test, its specifications can be
modified on the computer and retested. The final design * Accepting data or instructions (input)
specifications are released for production only when the * Storing data
engineer is satisfied that the part meets strength and other * Processing data
quality considerations. * Displaying results (output)
The CAM phase begins when the CAD phase is * Controlling and coordinating all operations inside a
complete. In this phase, the metal or other materials are computer
manufactured while complying with their specifications. In this section, we will discuss all these functions and
For this computer controlled manufacturing, tools are used see how one unit of a computer interacts with another to
to produce high quality products. perform these operations. Refer to Figure 1.11, which
shows the interaction between the different units of a
Robotics computer system.
Robots are computer-controlled machines mainly used in Input This is the process of entering data and instructions
the manufacturing process in extreme conditions where (also known as programs) into the computer system, The
{(16 } Computer Fundamentals and Programming in C

Data and
é; R Input Storage Output Results

cru
Control unit
'
aga Flow of data and instructions
— Control exercised by control unit

Figure 1.11 Block diagram


of a computer

data and instructions can be entered by using different only in binary form and the result of processing is also in
input devices such as keyboard, mouse, scanner, and binary form, the result cannot be directly given to the user.
trackball. Note that computers understand binary language, The output devices, therefore, convert the results available
which consists of only two symbols (0 and 1), so it is the in binary codes into a human-readable language before
responsibility of the input devices to convert the input data displaying it to the user.
into binary codes. Control The control unit (CU) is the central nervous
Storage Storage is the process of saving data and system of the entire computer system. It manages and
instructions permanently in the computer so that they can controls all the components of the computer system. It
be used for processing, The computer storage space not is the CU that decides the manner in which instructions
only stores the data and programs that operate on that data will be executed and operations performed. It takes care
but also stores the intermediate results and the final results of the step-by-step processing of all operations that are
of processing, performed in the computer.
A computer has two types of storage areas: Note that the CPU is a combination of the arithmetic
logic unit (ALU) and the CU. The CPU is better known
Primary storage Primary storage, also known as the main as the brain of the computer system because the entire
memory, is the storage area that is directly accessible by processing of data is done in the ALU, and the CU activates
the CPU at very high speeds. It isused to store the data and and monitors the operations of other units (such as input,
purts of programs, the intermediate results of processing, output, and storage) of the computer system.
and the recently generated results of jobs that are currently
being worked on by the computer. Primary storage space Processing The process of performing operations on the
is very expensive and therefore limited in capacity. data as per the instructions specified by the user (program)
Another drawback of main memory is that it is volatile is called processing. Data and instructions are taken from
in nature; that is, as soon as the computer is switched off, the primary memory and transferred to the ALU, which
the information stored gets erased. Hence, it cannot be performs all sorts of calculations. The intermediate results
used as a permanent storage of useful data and programs of processing may be stored in the main memory, as they
for future use. An example of primary storage is random might be required again. When the processing completes,
access memory (RAM). the final result is then transferred to the main memory.
Hence, the data may move from main memory to the ALU
Secondary storage Also known as auxiliary memory, multiple times before the processing is over.
this memory is just the opposite of primary memory, It
overcomes all the drawbacks of the primary storage area.
It is cheaper, non-volatile, and used to permanently store
data and programs of those jobs thal are not being currently
executed by the CPU. Secondary memory supplements
the limited storage capacity of the primary memory. An
example is the magnetic disk used to store data, such as C
and D drives, for future use. LAB SESSION—INSIDE THE
Output Output is the process of giving the result of data COMPUTER
processing to the outside world (external to the computer
system). The results are given through output devices such As a part ofthis chapter, the instructor must show the parts
as monitor, and printer. Since the computer accepts data of the computer to the students, as illustrated inFigure 1.12.
PS/2 Keyboard USK Serial! Serial? Graphics Secondary ethernet Sound card

Figure 1.12 Computer case and its parts

The following are some of the major parts of the These days, many computers come with a built-in sound
computer: chip, which makes it unnecessary to buy a separate card
unless a higher quality of sound is needed,
CPU The CPU is the brain of the computer. It performs
all calculations and controls the devices connected to Modem A modem (modulator-demodulator) is a device
the computer system. The faster the CPU, the quicker that enables the computer to use a telephone line to
programs can process the instructions. communicate and connect to the Internet,
RAM A fast CPU is of no use if the computer does not Network card A network card is used to connect the
have sufficient RAM. As discussed earlier, RAM is the computer cither to other computers or to the Internet (in
computer's memory which stores information used by case you are using a fast Internet connection such as cable
applications that are currently being executed by the or DSL).
CPU. More memory means more applications can be
Fans There are one or more fans inside the computer to
executed at the same time without degrading the system's
performance. keep the air moving and the computer cool.

Hard disk drive (HDD) The HDD of the computer is Cables There are multiple wires inside the computer
the secondary memory of the computer system where that are flat, ribbon-like cables. They are used to provide
information is stored permanently. All types of data, power and communication to the various parts inside the
computer.
documents, and programs are stored on the hard disk.
The larger the hard disk, the more the amount of data that
can be stored on the drive. Though the size of the HDD
does not affect the speed of execution of the program, it MOTHERBOARD
does affect the speed at which the user can access his/
her files. The motherboard, also known as the mainboard or the
parent board (refer Figure 1.13), is the primary component
Video card The video card is a board that plugs into
of a computer. It is used to connect all the components
the motherboard of the computer and generates images
of the computer. The motherboard is a printed circuit that
for display. Many video cards these days have their own
has connectors for expansion cards, memory modules, the
RAM and processor to enhance the speed of the graphics
processor, etc.
display, Many computers come with an in-built video chip.
In such a computer, a separate video card is used only if
the computer has to be used for high-end multimedia work 1.9.1 Characteristics of a Motherboard
or to play video games, A motherboard can be classified depending on the
Soundcard As with video cards, sound cards are expansion following characteristics:
boards that are used to enable a computer to manipulate * Form factor
sound. For example, sound cards allow the users to plug in * Chipset
speakers and a microphone. Some sound cards also provide * Type of processor socket used
the jacks for hooking your computer up to a common stereo. * Input-Output connectors
18 Computer Fundamentals and Programming in C

Input-Output connectors

Jumpers Disk drive and floppy drive connectors Case fan power supply
connector

Figure 1.13 Computer's motherboard

Form factor Form factor refers to the motherboard's of the computer (such as the processor and memory). In
geometry, dimensions, arrangement, and clectrical order to enhance the computer's upgradeability, one must
requirements. The industry has defined a few standards choose a motherboard that has the latest chipset integrated
for the form factors, so that they can be used in different in it, Some chipsets may include a graphics or audio chip,
brands of cases, which makes it unnecessary to install a separate graphics
card or sound card. However, in case you need very high
Integrated components Some of the motherboard’s
components are integrated into its printed circuitry. These quality of audio and visual capabilities, then you must
include the following: disable the graphics/audio chip in the BIOS setup and
install high-quality expansion cards in the appropriate slots.
* The chipset is a circuit that controls the majority of the
computer's resources such as the bus interface with the CMOS clock and battery The real-time clock (or RTC)
processor, cache memory, RAM, and expansion cards. is 4 circuit that is used to synchronize the computer's
* CMOS clock and battery signals. When the computer is switched off, the power
+ BIOS supply stops providing electricity to the motherboard.
* System bus and expansion bus You must have observed that when we turn on the system,
it always displays the correct time. This is because an
In addition to these, the latest motherboards also have
electronic circuit, called the complementary metal-
a number of onboard multimedia and networking devices oxide semiconductor (CMOS) chip, saves some system
(which can be disabled), such as integrated network
information, such as the time, date, and other essential
card, integrated graphics card, integrated sound card, and system settings,
upgraded hard drive controllers.
The CMOS chip is powered by a battery located on the
Chipset The chipset is an electronic circuit that basically motherboard. Information on the hardware installed in the
coordinates data transfers between the different components computer (such as the number of tracks or sectors on cach
Introduction to Computers

USB VGA

Figure 1.14 1/O connectors

hard drive) is stored in the CMOS chip. Since the CMOS it and to improve the heat transfer. The fan vents hot air
chip is quite slow, some systems prefer to copy the CMOS from the case and lets fresh air come in from outside.
chip's content into the RAM, which is a comparatively RAM connectors RAM is the primary storage area that
faster storage. This process of copying data into RAM is stores data while the computer is running. However, its
better known as memory shadow. contents are erased when the computer is turned off or
Have you noticed that, at times, the system time gets restarted, While the hard disk can store data permanently,
reset automatically, or the clock runs late’? This indicates we still need RAM because it is extremely fast when
that you need to change the battery. compared to mass storage devices such as hard drives.
BIOS The basic inpuV/output system (BIOS) is an interface Therefore, the fast processor accesses data from RAM
between the operating system and the motherboard. and not from the hard disk. The data is transferred from
The BIOS is stored in the read-only memory (ROM), the hard disk to the RAM, from where it is used by the
which cannot be rewritten. The BIOS uses data stored processor. RAM is available in the form of modules that
in the CMOS chip to know about the system's hardware plug into motherboard connectors.
configuration, Expansion slots Expansion slots are compartments into
‘To configure the BIOS, the user can use an interface which expansion cards can be inserted. Such curds render
known as B/OS setup. which can be accessed when the new features or enhance the computer's performance. For
computer is booting. To enter BIOS setup, the user must example, the AGP slot (also known as Accelerated Graphic
press the DEL key. Fl and F2 keys can also be used. Port) is a fast port used for graphics cards,
Processor socket The processor (also called the micro- 1/0 connectors The motherboard has a number of input~
processor) is the brain of the computer, The processor is output sockets (Figure 1.14) on its rear panel, some of
characterized by its speed or frequency, which is the rate at which include:
which it executes instructions. For example, an 800-MHz
* A serial port to connect some old peripherals
processor can perform 800 million operations per second.
A parallel port to connect old printers
The slot on the motherboard into which the processor is
USB ports to connect more recent peripherals such as
inserted is called the processor socket or slot. Irrespective mouse and pen drive.
of whether you use a slot or a socket, you must gently
RJ45 connector (also known as LAN or Ethernet port)
insert the processor, so that none of its pins are bent (it has
to connect the computer to a network. It corresponds to
hundreds of them). Usually, a concept called zero insertion
a network card integrated into the motherboard.
force (ZIP) is used. The ZIF sockets allow the processor to
Video graphics array (VGA) connector fo connect &
be inserted very gently and casily.
monitor. This connector interfaces with the built-in
When the computer is on, the processor is working
graphics card.
and it releases heat, which must be dissipated to keep the
Audio plugs that include the line in, line out, and
circuits from melting. Therefore, the processor is generally
microphone to connect sound speakers, hi-fi system, or
mounted on a cooler that is made of metal (such as copper microphone, This connector interfaces with the built-in
or aluminum), which conducts heat well. In addition to the
sound card.
cooler, there is also a fan to improve air circulation around

POINTS TO REMEMBER
* Modern are based y
computers-da of
on the principle
. A computer is anelectronic machine that accepts data
the stored program concept, which was introduced by
and instructions and performs computations on the
data based on those instructions. Sir John von Neumann in the late 1940s.
. Computers are used in allinteractive devices, such as * The speed of the computer is usually given in
nanoseco and picoseco
nds nds.
cellular telephones, GPS units, portable organizers,
ATM s,
and gas pumps.
G) Computer Fundamentals and Programming in C

© The term computer generation refers to the different of integrated circuits built
computers, with thousands
advancements of new computer technology. With on to a single silicon chip.
each new generation of computers, the circuitry has © Fifth-generation computers are manufactured using
become smaller and more advanced than that in its integrated chips (ICs) built with ultra-large scale
previous generation, integration (ULSI) technology.
© First-generation computers used a very large number © The CPU is a combination of the ALU and the CU. The
of vacuum tubes for circuitry and magnetic drums for CPU is known as the brain of the computer system.
memory. * The CU is the central nervous system of the entire
* Second-generation computers were manufactured computer system. It manages and controls all the
using transistors rather than vacuum tubes. components of the computer system.
* The development of the integrated circuit was the * The motherboard, also known as the mainboard or
hallmark of the third generation ofcomputers. the parent board, is the primary component of a
¢ The microprocessor started the fourth generation of computer.

| GLOSSARY
Tee "Kcomputer is an electronic machine thattakes computers all over the world.
instructions and performs computations based on those Memory shadow The process ofcopying data from CMOS
instructions. into RAM.
Expert systems Expert systems arecustom-written computer Program Aset of instructions executed by the computer.
programs that are ‘expert’ ina particular problem area, and Robotics Computers programmed to look, listen, and
embody a human expert’s knowledge, experience, and react to other sensory stimuli.
problem-solving strategies. They are being used in many Semiconductor devices Semiconductor devices are
areas such as medicine, chemistry, geology, meteorology, and electronic components that make use of the electronic
computer systems. properties of semiconductor materials (such as silicon
Garbage-in, garbage-out |f input data is wrong, then the and germanium). The conductivity of such devices can be
output will also be erroneous. controlled by introducing an electric field, by exposure to
making such
GUI A GUI is a type of user interface that enables users to light, and even pressure and heat, thereby
Interact with programs in more ways than typing. A GUI! devices excellent sensors.
offers graphical icons and visual indicators to display the Storage The process of saving data and instructions
Information and actions available toa user. The actions are permanently in the computer so that it can be used for
performed by direct manipulation ofthe graphical elements. processing.
Input The process of entering data and instructions into Stylus Astylus isan electronic pen that looks like a small
the computer system. ballpoint pen.
Integrated circuit Also called a chip or microchip, an IC Transistor A transistor is a semiconductor device that is
is a semiconductor wafer on which thousa millions used to amplify and switch electronic signals. Although
ornds
of tiny resistors, capacitors, and transistors are fabricated. some transistors are packaged individually, others are
it can be used as an amplifier, oscillator, timer, counter, usually found embedded in ICs.
computer memory, or microprocessor. Vacuum tube A vacuum tube is a device used to amplify
InternetIt is a network of networks that connects electronic signals.

EXERCISES
Fill in the Blanks 4. The speed of computers is expressed in or

1, Aprogram is the
based on 5. Raw facts or figures are called
2. Computers operate on
calculations in a second.
6. is an example of primary memory.
3. Computers can perform
and______ are examples offirst-generation 6. The brain of the computer is the
computing devices. (a) control unit (b) ALU
. Second-generation computers were first developed for {e) CPU (d) All of these
the industry.
3 packages allow easy manipulation and analysis State True or False
of data organized in rows and columns.
1. Computers work on the GIGO concept.
|. CRAY-1, CRAY-2, Control Data CYBER 205, and ETA A-10
are -
2. Lnanosecond = 1x10"™ seconds,
3. Floppy disks and hard disks are examples of primary
enables the computer to use a telephone line memory.
to communicate
and connect to the Internet.
4. First-generation computers used a very large number of
connector is used to connect a monitor. transistors.
hs concept was introduced by Sir John von
5. First-generation computers could be programmed only
Neumann
in the late 1940s.
in binary language.
. Android Jellybean, Windows, and iOS are all examples of
ALGOL is used in the third generation of computers,
popular operating systems used in and
. Fifth-generation computers are based on Al.
f is an interface between the operating system Network computers have more processing power,
memory, and storage than a desktop computer.
and the motherboard.
. RAM stores the data and parts of program, the
Multiple-choice Questions intermediate results of processing, and the recently
generated resultsofjobs that are currently being worked
1, Which was the first commercial computer delivered to a
on by the computer.
business client?
10. Aserial port is used to connect old printers,
(a) UNIVAC (b) ENIAC
{c) EDSAC (d) Noneof these Review Questions
. Which technology was used to manufacture second- 1. Define a computer.
generation computers? 2. Differentiate between data and Information,
(a) Vacuum tubes (b) Transistors 3. Differentiate between primary memory and secondary
(c) ICs {d) None of these memory.
. Time sharing operating systems were used in which 4. Write a short note on the characteristics of a computer.
generationof computers? 5. Computers work on the garbage-in, garbage-out
(a) First {b) Second concept. Comment.
(c) Third (d) Fourth 6. Explain the evolution of computers. Further, state how
. Choose the computer languages that are specially computers in one generation are better than their
designed for the fifth generationofcomputers. predecessors.
. Broadly classify computers based on their speed, the
(a) ALGOL ({b) SNOBOL amount ofdata that they can hold, and price.
(c) Lise {d) Prolog Discuss the variants of microcomputers that are widely
. Web TV is an exampleof used today,
(a) supercomputer {b) minicomputer . Explain the areas in which computers are being applied
(c) network Computer (d) laptop to carry out routine and highly-specialized tasks,
put and Output Devices

TAKEAWAYS © Soft copy devices


© Input devices * Optical devices
* Hard copy devices
* Pointing devices * Audiovisual input devices
* Output devices

and the
an inverted T-type fashion between the typing
r on the
INPUT DEVICES numeric keys, and are used to move the curso
addit ion to the arrow keys,
screen in small increments. In
keys) , such as:
An input device is used to feed data and instr
uctions into there are other cursor keys (or navigational
uter
‘a computer, In the absence of an input device, a comp + Home and End to move the cursor to the begin
ning and
on,
would have only been a display device, In this secti end of the current line, respectively
es,
we will read about some of the widely used input devic * Page Up and Page Down to move the curso
r up and
into diffe rent group s. ly.
Figure 2.1 categorizes input devices down by one screen at a time, respective
existing
+ Insert to enter a character between two
2.1.1 Keyboard characters
ion
ters. + Delete to delete a character at the cursor posit
The keyboard is the main input device for compu
Computer keyboards look very similar to the keybo ards Other common control keys on the keyboard include
Print Screen,
of typewriters, with some additional keys, as show n in Control (Ctrl), Alternate (Alt), Exeape (Esc),
Windows
Figure 2.2. Pause, the Windows or Start key (Microsoft
s
Using a keyboard, the user can type & document, use logo), and a shortcut key. The shortcut key is used to acces
right mous e butto n.
keystroke shortcuts, access menus, play games
, and the options available by pressing the
perform numerous other tasks. Most keybo ards have The Esc key cancels the selected option, and the Pause
between 80 and 110 keys, which include the following: key suspends a command/process in progress. Finally, the
n as an
bet. Print Screen key captures everything on the scree
Typing keys These include the letters of the alpha image. The image can be pasted into any docu ment .
RTY for
The layout of the keyboard is known as QWE
its first six letters. The QWERTY pattern has been a
were
standard right from the time computer keyboards
introduced.
Numeric keys These include a set of keys, arranged in the
data
same configuration found on calculators to speed up
entry of numbers. When the Num Lock key is set to ON,
~,
the user can type numbers, dot, or input the symbols /, *,
and +. When the Num Lock key is set to OFF, the numer ic
Inside the Keyboard
keys can be used to move the cursor on the screen,
Function keys These are used by applications and A keyboard is like a miniature computer that has its own
operating systems to input specific commands, They processor and circuitry to carry information to and from
are often placed on the top of the keyboard in a single that processor. The circuitry has a key matrix, which is
row. Function keys can be programmed so that their a grid of circuits underneath the keys. Each circuit is
functionality varies from one program to another, broken at a point below each key. When a key is pressed,
it corresponds to pressing a switch, thereby completing
Control keys These are used to handle control of the
the circuit,
cursor and the screen. Four arrow keys are arranged in
Input and Output Devices Gs

Input devices

Keyboard Pointing devices Handheld devices Optical devices Audio/Visual devices

Mouse Pen Barcode readers

Trackball Touchscreen Scanners

Trackpad Joystick OCR

OMR

MICR

Figure 2.1 Categories of input devices

2.1.2 Pointing Devices


A pointing input device enables the users to easily control
the movement of the pointer to select items on a display
re) screen, to select commands from commands menu, to draw
fTITTIi11i.
— a
a" graphics, etc. Some examples of pointing devices include
mouse, trackball, light pen, joystick, and touchpad.

Mouse
The mouse is an input device that was invented by Douglas
Engelbart in 1963. It is the key input device used in a
graphical user interface (GUI). It can be used to handle the
Figure 2.2 Keyboard pointer easily on the screen to perform various functions
such as opening a program or file. With the mouse, the users
Source: digital art/FreeDigitalPhotos.net
no longer need to memorize commands, which was earlier
a necessity when working with text-based command line
environments like MS-DOS. A mouse is shown in Figure 2.3,

When the processor finds a closed circuit, it compares Scroller


the location of
that circuit on the key matrix to the character
map in its read-only memory (ROM). A character map is
a lookup table that tells the processor what each keystroke
or a combination of keystrokes represents. For example,
the character map tells the processor that pressing the key
*¢' corresponds to a small letter *¢” but the keys “Shift and Right button
*e’ pressed together is a °C”.
Note that a computer can also use separate character
Left button
maps, overriding the one found in the keyboard. This is
usually done when the user is typing in a language that Figure 2.3. Mouse
uses letters that don’t have English equivalents on a
keyboard with English letters. The mouse has two buttons and a scroll wheel. It can
be held in the hand and easily moved, without lifting,
Advantage The keyboard is casy to use and inexpensive. along a hard flat surface to move the cursor to the desired
location—up, down, left, or right. Once the mouse is
Disadvantages placed at the appropriate position, the user may perform
* The keyboard cannot be used to draw figures. the following operations:
* The process of moving the cursor to another position is Point Placing the pointer over the word or the object on
very slow. Mouse and other pointing devices are more the screen by moving the mouse on the desk is termed as
apt for this purpose. pointing.
(4 Computer Fundamentals and Programming in C

Pressing cither the left or the right button of the


mouse is known as clicking. Clicking a mouse button
initiates some action; for example, when you click the
right button by pointing the mouse on a word, a menu pops
up on the screen. When you move the pointer over the icon
of an application, say Internet Explorer, and double-click
on it, then it opens that application for you. Trackball
Drag Dragging means pointing to a desired location while
pressing the left button.
Fig. 2.4 Trackball on keyboard
Scroll The scroll wheel, which is placed in between the
Source: Eugene Sergeev/Shutterstock
left and right buttons of the mouse, is used to vertically
scroll through long documents,
Today, the mouse has become so important that every
user buys a mouse when he or she buys a computer. The
mouse is specially used to create graphics such as lines,
curves, and freehand shapes on the screen. It is connected
to a serial or a universal serial bus (USB) port on the system
unit. Some ofthe popular mouse types are as follows:
Mechanical mouse This type of mouse has a rubber or
metal ball at its bottom and an electronic circuit containing
sensors, When the mouse is moved over a flat surface, the
sensors detect the direction of movement of the ball. The Figure 2.5 Trackball used like a mouse
electronic circuit translates the movement into signals and Source: Andrew Buckin/Shutterstock
feeds it as input to the computer.
Optical mouse The optical mouse is more advanced (identical to mouse buttons) near the trackball, cither to
than the mechanical mouse, It contains a ball inside. The select objects or to position the cursor for text entry. This
movement of the mouse is detected using laser technology, is shown in Pigure 2.5.
by using optical sensors. To move the pointer, the ball is rotated with the thumb,
fingers, or the palm of the hand. The advantage of a
Cordless mouse A cordless or wireless mouse is not trackball over a mouse is that the former is stationary,
connected to the computer. The movement of the mouse is and so it does not require much space to use, Moreover,
detected using radio waves or infrared light waves. individual trackballs can be placed on any type of surface,
Advantages including the user's lap. These advantages make trackballs
* The mouse is easy to use and can be used to quickly very popular pointing devices for portable computers and
place the cursor anywhere on the screen. mobile phones.
* Italso helps to quickly and easily draw figures. Note that the working ofa trackball is identical to that
* Itis inexpensive. of mouse.
* Its point-and-click capabilities make it unnecessary to Advantages
remember and type in commands. * The trackball provides better resolution.
Disadvantages * It occupies less space.
* The mouse needs extra desk space to be placed and * It is easier to use as compared to a mouse as its use
moved easily. involves less hand and arm movements.
* The ball in the mechanical mouse must be cleaned to Di
remove dust from it. The trackball chamber is often covered with dust, so it
must be cleaned regularly.
Trackball
A trackball is a pointing device that is used to control the Touchpad
position of the cursor on the screen, It is usually used in A touchpad (or trackpad), as shown in Figure 2.6, is a
notebook computers, where it is placed on the keyboard, small, flat, rectangular stationary pointing device with
as shown in Figure 2.4. a sensitive surface of 1.5—2 square inches, The user has
The trackball is nothing but an upside-down mouse to slide his or her fingertips across the surface of the pad
where the ball rotates in place within a socket. The user to point to a specific object on the screen. The surface
rolls the ball to position the cursor at an appropriate translates the motion and position of the user’s fingers to
position on the screen and then clicks one of the buttons a relative position on the screen. There are also buttons
Input and Output Devices 25

buttons, called switches, whose position can also be read


by the computer,
The lever of ajoystick moves in all directions to control the
movement of the pointer on the computer screen. A joystick
is similar to a mouse, but with the mouse, the cursor stops
moving as soon as you stop moving the mouse. However,
in case of a joystick, the pointer continues moving in the
direction to which the joystick is pointing. To stop the pointer,
the user must return thejoystick to its upright position,

Figure 2.6 Touchpad Stylus


Source: Yulia Nikulyasha Nikitina/
A stylus (shown in Fig. 2.8) is a pen-shaped input device
Shutterstock/OUP Picture Bank
used fo enter information or write on the touchscreen of
around the edge of the pad that work like mouse buttons. a handheld device
Touchpads are widely used in laptops, and are in built on It is a small stick
the laptop keyboards, They can also be attached to a PC or that can also be used
be used with personal digital assistants (PDAs) and iPods. to draw lines on a
The working of a touchpad is similar to that of amouse Surface as input into
or a trackball. The pressure of the finger on the surface a device, choose an
leads to a capacitance effect, which is detected by the option from a menu,
sensors, The sensors send appropriate signals to the CPU, move the cursor to
which interprets them and displays the pointer on the another location
screen on the sereen, take
Advantages notes, and create
* Touchpads occupy less space. short messages. The
* They are casier to use as compared to a mouse as their stylus usually slides
use involves less hand and arm movements. into a slot built into
Figure 2.8 Stylus
* A touchpad is in-built in the keyboard, and hence the device for that
Source: Photodisc/OUP Picture Bank purpose
negates the need to carry an extra device
Touchscreen
2.1.3 Handheld Devices
A handheld device is a pocket-sized computing device Atouchsereen (shown in Figure 2.9) is a display screen that
with a display sereen and touch input and/or a miniature can identify the occurrence and position of a touch inside
keyboard, Some common examples of handheld devices the display region, The user can touch the sereen either by
include smartphones, PDAs, handheld game consoles, using a finger or a stylus. The touchscreen facilitates the
and portable media players (c.g., iPods). In this section, users fo interact with what is displayed on the sercen in a
we will read about joystick stylus (pen) and touchscreens, straightforward manner, rather than in an indirect way by
which are the means to input data to handheld devices using 4 mouse or a touchpad, Touchscreens make using
another input device redundant, since the user can interact
with the sereen by directly touching it. Such touchscreen
Joystick
displays are available on computers, laptops, PDAs, and
A joystick = (refer mobile phones.
Figure 2.7) is a cursor
control device widely
used in computer
games and computer-
aided design (CAD)
computer-aided
manufacturing (CAM)
applications. It
consists of a handheld
lever that pivots on
one end and transmits
its coordinates to a
Figure 2.7 Joystick Figure 2.9 Touchscreen
computer. A joystick
Source: Viktor Kunz/Shutterstock has one or more push Source: Gareth Boden/OUP Picture Bank
26 Computer Fundamentals and Programming in C

‘ouchscreen monitors are an casy way of entering Disadvantages


information into the computer (or mobile phone, etc). * Barcode readers must be handled with care. If they
Touchscreen monitors have become more and more develop a scratch, the user may not be able to read the
commonplace as their price has steadily dropped over the code.
past decade, These days, touchscreen monitors are widely * They can interpret information using a limited series of
used in different applications including point-of-sale thin and wide bars. To interpret other unique identifiers,
(POS) cash registers, PDAs, automated teller machines the bar display area must be widened.
(ATMs), car navigation screens, mobile phones, gaming
consoles, and any other type of appliance that requires the Image Scanner
user to input and receive information instantly,
A scanner (shown in Fig. 2.10) is a device that captures
2.1.4 Optical Devices images, printed text, and handwriting, from different
sources such as photographic prints, posters, and magazines
Optical devices, also known as data-scanning devices, and converts them into digital images for editing and
use light as a source of input for detecting or recognizing display on computers, Scanners come in handheld, feed-in,
different objects such as characters, marks, codes, and and flatbed types, and for scanning cither colour imuges,
images. These devices convert these objects into digital black-and-white images, or both. While lower resolution
data and send it to the computer for further processing. scanners are adequate for capturing images for computer
Some optical devices that are discussed in this section display, very high resolution scanners, on the other hand,
include barcode readers, image scanners, optical are used for scanning of high-resolution printing, Some
character recognition (OCR) devices, optical mark scanners have software like Adobe Photoshop to help the
readers (OMR), and magnetic ink character recognition user resize or modify a captured image.
(MICR) devices.

Barcode Reader
A barcode reader (also price scanner or POS scanner) is
a handheld input device that is used to capture and read
information stored in a barcode. It consists of a scanner,
a decoder, and a cable used to connect the reader to a
computer, The function of the barcode reader is to capture
and translate the barcode into numerals and/or letters. It
is connected to a computer for further processing of the
captured information, This connection is achieved through
a serial port, keyboard port, or an interface device called
awedge. Figure 2.10 Flatbed image scanner
Abarcode reader works by directing a beamof light across Source: Mile Atanasov/Shutterstock
the barcode and measuring the amount of light reflected
back. The dark bars reflect less light when compared to the Some scanners can be connected to the computer using
amount of light reflected by the white spaces between those a small computer system interface (SCSI). Some major
bars. The scanner converts this light energy into electrical manufacturers of scanners are Epson, Hewlett-Packard,
energy, The decoder then converts these signals into data Microtek, and Relisys, The basic types of image scanners
and sends it to the computer for processing. are flatbed, hand, film, and drum scanners.
These days, barcode readers are widely used in The scanners that we see in our colleges or offices are
following areas: flatbed scanners. In this type, the object to be scanned is
placed on a glass pane and an opaque cover is lowered over
* Generate bills in supermarkets and retail stores
it. A sensor and light move along the pane, reflecting off
* Take stock of inventory in retail stores
the image placed on the glass. The cover is used to prevent
* Check out books from a library other light from interfering, and the image becomes visible
* Track manufacturing and shipping movement
to the detector.
* Keep track of employee login
A hand image scanner has to be manually moved across
* Identify hospital patients the object or image to be scanned. The scanner produces
* Tabulate the results of direct mail marketing returns
light from green light emitting diodes (LEDs), which
* Tag honeybees used in research
highlight and scan the image onto a computer for further
Advantages processing. However, these days, 3D image scanners have
* Barcode readers are inexpensive. become the most popular form of hand scanners, as they
* They are portable. are able to compensate for jerky hand movements during
* They are handy and easy to use. scanning.
Input and Output Devices @

Film scanners are usually used in photography and In OCR processing, the analysis of the scanned i
slides. The slide or negative film is first inserted in strips is done to detect light and dark areas so as to identify each
of six or less frames into the film scanner, and then moved letter or numeral. When a character is recognized, it is
across a lens and sensor to capture the image. converted into an ASCII code.
While handheld and film scanners use charge coupled OCR has facilitated users to store text documents as
device (CCD) arrays, drum scanners. on the other hand, text files (rather than as images, as in case of scanners).
use photo multiplier tubes. Drum scanners are mounted Hence, the text files occupy much less storage space and
on an acrylic cylinder that rotates while passing the object can be easily edited. These days, OCR is widely used in
in front of precision optics, which in tum transfers the the following areas:
image information to the photo multiplier tubes, Most * Digitize and preserve documents in libraries
drum scanners use three matched PMTs that are capable * Process checks and credit card slips
of detecting red, blue, and green light. The light of the + Sort letters for speeding up mail delivery
object being scanned is separated into red, blue, and green Letus takeareal-world example to understand the power
beams. Drum scanners are very expensive and are often
of OCR. The police department usually has all the criminal
used for high-end applications of film.
records stored in large file cabinets. Seanning millions of
Advantages pages to find a particular record is not only tedious and
* Any printed or handwritten document can be scanned error-prone but also an expensive process. However, if
and stored in a computer for further processing. OCR is used to convert the pages into computer-readable
* The scanned and stored document will never deteriorate text, the police can casily search through the entire
in quality with time. The document can be displayed history in a few seconds. OCR technology can be easily
and printed whenever required. understood from Figure 2.11.
* There is no fear of loss of documents. The user can scan Advantages
important documents and store them permanently in the + Printed documents can be converted into text files.
computer. + Advanced OCR can recognize handwritten text and
Disadvantages convert it into computer-readable text files.
* Scanners are usually costlier than other input devices. Disadvantages
* The documents that are scanned and stored as images + OCR cannot recognize all types of fonts.
have a higher size as compared to other equivalent text
+ Documents that are poorly typed or have strikeover
files. cannot be recognized.
* Text documents are scanned and stored as images. + Very old documents when passed through OCR may not
Therefore, they occupy more space and are also convert into anexact copy of the text file. This is because
uneditable because computers cannot interpret
some characters may not have been recognized properly.
individual characters and numbers in the image.
In such cases, the user has to manually edit the file.

Optical Character Recognition (OCR) Device Optical Mark Recognition (OMR) Device
Optical character recognition is the process of converting Optical mark recognition is the process of electronically
printed materials into text or word processing files that can extracting data from marked fields, such as checkboxes
be easily edited and stored. The steps involved in OCR and fill-in fields, on printed forms. The optical mark reader,
include: as shown in Figure 2.12, is fed with an OMR sheet that has
* Scanning the text character by character pen or pencil marks in pre-defined positions to indicate
+ Analysing the scanned image to translate the character each selected response (¢.g., answers for multiple-choice
images into character codes (¢.g., ASCII) questions in an entrance examination).

Printed
documents:

4 ‘Scans the documents and


makes a bitmap of size
50-150 KBper page
Figure 2.11 OCR technology
((28 | Computer Fundamentals and Programming in C
———— routing number, account number, and, in some cases, the
amount on the cheque) for processing to the receiving party.
MICR characters are usually printed in E-13B or
CMC-7 fonts. Each font is made up of a series of numbers
and symbols specifically designed for readability on high-
speed check-sorting machines. The symbols provide
beginning and end points for cach group of numbers in
order to enable the machine to determine what cach series
of numbers mean. To print the magnetic characters on the
Figure 2.12 Optical mark reader
check is a critical task, and the line placement, character
placement, skew, quality, and the positioning of the line
The OMR sheet is scanned by the reader to detect the in the MICR clear band area (depicted by an arrow in
presence of a mark by measuring the reflected light levels. Figure 2.13) must be done very precisely.
The dark or the marked areas reflect less light than the MICR is widely used to enhance security, speed up the
unmarked ones, The OM reader interprets this pattern sorting of documents, and minimize the exposure to check
of marks and spaces, and stores the interpreted data in a fraud. Let us take a real-world problem to understand how
computer for storage, analysis, and reporting, The error rate MICR reduces risk to fraud. If a person gives a cheque
for OMR technology is less than 1%. For this reason, OMR produced using a colour photocopying machine, the
is widely used for applications in which large numbers of magnetic ink line will either not respond to the magnetic
hand-filled forms have to be quickly processed with great fields, or will produce an incorrect code when scanned
accuracy, such as surveys, reply cards, questionnaires, using an MICR reader. The MICR device even rejects
ballots, or sheets for multiple-choice questions. cheques issued by an account owner who has a history of
writing bad cheques.
Advantage
Optical mark readers work at very high speeds. They can 2.1.5 Audiovisual Input Devices
read up to 9000 forms per hour. Today, all computers are multimedia-enabled_ that is,
Disadvantages computers not only allow one to read or write text, but also
+ It is difficult to gather large amounts of information enable the user to record songs, view animated movies,
using an OMR. etc. Hence, in addition to having a keyboard and a mouse,
+ Some data may be missing in the scanned document. audio-video devices have become a necessity today.
+ Itis a sensitive device that rejects the OMR sheet if itis
folded, torn, or crushed. Audio Devices
Magnetic Ink Character Reader Audio devices are used to either capture or create sound.
They enable computers to accept music, speech, or sound
Magnetic ink character reader (MICR) is used to verify effects for recording and/or editing. Microphones and CD
the legitimacy of paper documents, especially bank players are examples of two widely used audio input devices.
checks, It consists of magnetic ink printed characters that A microphone feeds audio input to the computer.
can be recognized by high-speed magnetic recognition However, the audio input must be converted into digital
devices (refer Figure 2.13), The printed characters provide data before being stored in the computer. For this, the
important information (such as cheque number, bank computer must have a sound card. The sound card is a
hardware unit that converts analog signals generated
through the microphone into digital data, so that it can
be stored in the computer. When the user wants to hear
the pre-recorded audio input, the sound card converts the
digital data into equivalent analog signals and sends them
Pay DATE:
to the speakers, This process is depicted in Figure 2.14.
ae) A computer with a microphone and speakers can be
RUPEES used to make telephone calls and do videoconferencing
(using a web camera or ‘webcam’) over the Internet.

Video Input Devices

Magnetic
ink character recognition
Video input devices are used to capture video from the
outside world into the computer. Here, the term video
Figure 2.13 A cheque containing magnetic ink characters means moving picture along with sound (as in television).
printed on it As we have sound cards to convert analog audio signals
= W
Input and Output Devices (9 i

a Sound card
4 Speakers
The user speaks in The sound card converts analog ‘The sound card converts digital data stored
the microphone signals into digital data sothat itcan in the computer into analog signals and
be stored in thecomputer sends ittothe speakers sothat users may
hearthe sound

Figure 2.14 Recording and retrieving audio data

into digital data and vice versa, we also have video cards * They can be used to record memorable moments in
to convert analog video signals to digital data fo store it one’s life.
in the computer (and vice versa). Digital camera and web * They can also be used for security purposes,
camera are popular examples of video input devices.
Disadvantages
A digital camera as shown in Figure 2.15(a) is a * Audio input devices are not effective in noisy places,
handheld and easily portable device used to capture + With audio input devices, it is difficult to clearly
images or videos. The digital camera digitizes image or distinguish between two similar sounding words such
video (converts them into Is and 0s) and stores them on
as ‘sea’ and ‘see’.
a memory card. The data can then be transferred to the * Videos and images captured using video input devices
computer using a cable that connects the computer to the have very big file sizes, and they must be compressed
digital camera, Once the images or videos are transferred before being stored on the computer.
to the computer, they can be easily edited, printed, or
transmitted (c.g., through e-mails),
As with digital cameras, web cameras (also called OUTPUT DEVICES
webcams) too capture videos that can be transferred
via the Internet in real-time, Web cameras are widely Any device that outputs/gives information from a computer
used for videoconferencing. They are not very costly, can be called an output device. Basically, output devices
and this is one reason why they are so widely used for are electromechanical devices that accept digital data (in
security and privacy purposes. Webcams are also used the form of 0s and 1s) from the computer and convert them
4s security cameras, since PC-connected cameras can be into human-understandable language.
used to watch for movement and sound, recording both Since these days all computers are multimedia-enabled,
when they are detected, These recordings can then be the information from computers is usually output in cither
saved in the computer and used to detect or investigate visual or auditory format. Monitors and speakers are two
theft or any other crime. A web camera is shown in widely used output devices. These devices provide instant
Figure 2.15(b). feedback to the user's input. For example, monitors
display characters as they are typed. Similarly, speakers
Advantages play a song instantly when the user selects one from a
* Audio devices can be used by people who are visually playlist. Other examples of output devices include printers,
impaired. plotters, and projectors.
* Audio input devices are best used in situations where In this section, we will discuss these output devices.
users want to avoid input through keyboard or mouse. However, before going into their details, let us classify the
+ Video input devices are very useful for applications output devices based on whether they give a hard copy or
such as videoconferencing, a soft copy output (refer Figure 2.16).

2.2.1 Soft Copy Devices


Soft copy output devices are those that produce an
electronic version of an output—for example, a file that is
stored on a hard disk, CD, or pen drive—and is displayed
on the computer screen (monitor). Features of a sofi copy
@) (b)
output include the following:
Figure 2.15 Video input devices (2) Web camera * The output can be viewed only when the computer is on.
(b) Digital camera + The user can easily edit soft copy output.
Computer Fundamentals and Programming in C

Hard
copy devices

Projector Speaker

Figure 2.16 Classification of output devices

(a) (b) {e)


Figure 2.17 Types of monitors (a) CRT (b) LCD (c) Plasma

* Soft copy cannot be used by people who do not have a glass tube. The ray is a stream of electrons that come
computer. out from a heated cathode into the vacuum, While
* Scarching for data in a soft copy is easy and fast. electrons are negative, the anode, on the other hand, is
* Electronic distribution of material as soft copy is positive, so it attracts the electrons coming out of the
cheaper, It can be done easily and quickly. cathode. That is, the focusing anode focuses the stream
of electrons to form a tight beam that is then accelerated
Monitors by an accelerating anode. This tight, high-speed beam of
The monitor is a soft copy output device used to display electrons flies through the vacuum in the tube and hits
video and graphics information generated by the computer the flat screen at the other end of the tube, This screen is
through the video card. Computer monitors are similar to coated with phosphor, which glows when struck by the
television screens but they display information at a much beam, thereby displaying a picture, which the user sees
higher quality, The monitor is connected to cither the VGA on the monitor,
or the digital video interface (DVI) port on the video card
(on the motherboard or separately purchased).
Monitors come in three variants—cathode ray
tube (CRT), liquid crystal display (LCD), and plasma Note that, colour CRT monitors contain three electron
(refer Figure 2,17), While CRT monitors look much guns (one each for red, blue, and green).
like traditional televisions and are very huge in size, ach pixel ordot on the screen has three phosphors (red,
LCD monitors on the other hand are thinner, offering blue, and green). When the beam from these guns is
equivalent graphics quality. However, these days, LCD focused on the phosphors, they light up. Byvarying the
monitors are replacing CRT monitors as they are cheaper intensities ofthe beam, the user can obtain different
and occupy less space on the desk. Most monitors have colours.
a size range of 15’ to 21’ or more (where size is defined
as a diagonal measurement from one corner of the screen
to the other). Advantages
CRT monitor CRT monitors work by firing charged * CRT monitors provide images of good quality (bright as
well as clear).
electrons at a phosphorus film (refer Figure 2.18). When
electrons hit the phosphor-coated screen, they glow, * CRT monitors are cheapest when compared to LCD and
thereby enabling the user to see the output. plasma monitors.
In a CRT, the cathode (negative terminal) is a heated * The images are clear even when you try to view it from
filament that is placed in a vacuum created inside a an angle.
Input and Output Devices GI

Most LCD displays use active matrix technology


which a thin film transistor (TFT) arranges tiny transistors
and capacitors in a matrix on the glass of the display. To
refer to a particular pixel, the proper row is turned on, and
then a charge is sent through the correct column. Since all
the other rows are switched off, only the capacitor at the
designated pixel receives a charge.
Passive matrix technology is the other type of LCD,
which uses a grid of conductive metal to charge each
pixel. Although these LCDs are cheaper, they are hardly
used today because of slow response time and imprecise
voltage control compared to active matrix technology.
Cathode ray tube Advantages
Figure 2.18 Working of a CRT monitor + LCD monitors are very compact and lightweight.
* They consume less power.
Disadvantages * They do not suffer from geometric distortion.
* CRT monitors occupy a large space on the desk. * There is little or no flicker of images (depending on the
* They are bigger in size and weight and therefore difficult backlight technology used).
to move from one place to another when compared with * They are more reliable than CRTs.
other types of monitors. * They can be made in almost any size or shape.
* Power consumption is higher than the other monitors. * They cause less eye fatigue.
LCD Monitor An LCD monitor (shown in Figure 2.19)
is a thin, flat, electronic visual display that uses the light Disadvantages
* They are more expensive than CRTs.
modulating properties of liquid crystals, which do not emit
* Images are not very clear when tried to view from an
light directly, LCD screens are used in a wide range of
applications ranging from computer monitors, televisions, angle.
instrument panels, aircraft cockpit displays, signage, Plasma monitor Plasma monitors are thin and flat
etc,, 10 consumer devices such as video players, gaming monitors widely used in televisions and computers.
devices, clocks, watches, calculators, and telephones. The plasma display contains two glass plates that have
hundreds of thousands of tiny cells filled with xenon and
Polarizing Liquid crystal layer neon gases. The address clectrode and the transparent
filters display electrode are sandwiched between the glass plates.
The display electrode is covered by a magnesium oxide
protective layer and is arranged in horizontal rows along
the screen, while the address electrodes are arranged in
vertical columns, thereby forming a grid-like structure as
shown in Figure 2.20.

Figure 2.19 Working of a LCD monitor

These days, LCDs have become so popular that there are


replacing the traditional CRT displays at a fast pace. LCD
screens are more compact, lightweight, portable, more
reliable, and casier on the eyes. LCDs are more energy
efficient and offer safer disposal than CRTs. It is because of
their low electrical power consumption that they are widely
being used in battery-powered electronic equipment,
LCD technology is based on the principle of blocking
light. The LCD consists of two pieces of polarizing
filters (or substrates) that contain a liquid crystal material
between them. A backlight creates light, which is made
to pass through the first substrate. Simultaneously, the
electrical currents cause the liquid crystal molecules to
align, thus allowing varying levels of light to pass through
to the second substrate and create the colours, and hence
images are seen on the screen. Figure 2.20 Working of a plasma monitor
32. Computer Fundamentals and Programming in C
‘To ionize the gas in a particular cell, the electrodes that on a big screen, the projector first displays that image
intersect at that cell are charged at least thousands of times (represented in the video signal) onto a small screen inside
within a small fraction of a second (charging cach cell the projector itself, which is then projected onto the final
in turn). sercen using bright light and a lens. The lens is shaped in
Once the intersecting electrodes are charged, an electric such a way that it takes the small image and turns it into a
current begins to flow through the gas in the cell. The dramatically larger one.
current creates a rapid flow of charged particles, thereby Projectors can be broadly classified into two categories
stimulating the gas atoms to release ultraviolet photons. depending on the technology they use.
When these UV photons hit a phosphor atom in the cell, LCD projector LCD projectors make use of their own light
one of phosphor’s electrons jumps to a higher energy level,
to display the image on the screen/wall. These proj
and the atom heats up. When the electron falls back to its
are based on LCD technology. To use these projectors, the
normal level, it rele: es energy in the form of a visible
room must be first darkened, else the image formed will
light photon, be blurred.
Advantages Digital light processing (DLP) projector DLP projectors
* The technology used in plasma monitors allows
use a number of mirrors to reflect the light. When using
producing a very wide sereen using extremely thin
the DLP projector, the room may or may not be darkened
materials, because it displays a clear image in both situations.
* Very bright images are formed which look good from
almost every angle.
Speakers
* These monitors are not heavy and are thus easily
Initially, computers were designed to be used only
portable.
for scientific purposes, but later, with the advances in
Disadvantages technology, computers became so popular and inexpensive
* These monitors are very expensive. that they are now used in almost every sphere of our day-
* They have a high power consumption. to-day lives. Today, all business and home users demand
* Since the images are phosphor-based, at times, they audio capabilities from their computers. For this purpose,
may suffer from flicker speakers were developed in different sizes and shape:
and with different powers and sound quality, With all
Projectors these types of speakers, the user can enjoy music, movie,
A projector (Figure 2.21) is a device that takes an image or a game, and the voice will be spread through the entire
from a video source and projects it onto a screen or another room. With good quality speakers, the voice will also be
surface, These days, projectors are used for a wide range audible even to people sitting in another room or even to
of applications, varying from home theater systems for neighbours!
projecting movies and television programs onto a screen However, in case the user wants to enjoy loud music
much larger than even the biggest available television, to without disturbing the people nearby, a headphone can
organizations for projecting information and presentations be used. Headphones are small devices that fit in or on
onto screens large enough for rooms filled with many the car, and give about the same quality and power of the
people, Projectors also allow users to change/adjust sound, as the speakers, only to the listener. Most of today’s
some features of the image such as brightness, sharpness, headphones feature some noise-cancelling technologie:
and colour settings, similar to the features available in so that the listener may listen to only the sound from
a standard television. Projectors are now available in a the speakers and not anything else from the surrounding
variety of different shapes and sizes, and are produced by environment.
many different companies. Users often use headphones to chat with people over
The projector works by receiving a video signal from the Internet. With headphones, they are assured that
some external device such as a DVD player or a computer the conversation is heard only by them, However, in
and projects that signal onto a sercen. To display the image addition to the headphones, they are also required to
use a separate microphone to talk to the other person
Hence, another device called the headset was developed

9 |
to allow users to talk and listen at the same time, using
the same device. Headsets are widely used in call centers
and other telephone-intensive jobs, and for personal use
on the computer to facilitate comfortable simultancou
conversation and typing. Figure 2.22 shows the various
audio devices used with computers,
Although every computer has a built-in speaker, an
Figure 2.21 Projector external speaker disables this lower-fidelity built-in
Source: olegbush/Shutterstock speaker. Speakers available in the market have a wide
Input and Output Devices 33

HB 6
information. Colour printers can also be set to print only
in monochrome. These printers are more expensive, so if
the users do not have a specific need for colour and usually
take a lot of printouts, they will find a black-and-white
printer cheaper to operate.

Resolution The resolution of a printer means the


Figure 2.22 Audio devices (a) Speakers (b) Headphones sharpness of text and images rendered on paper. It is
(c) Headset usually expressed in dots per inch (dpi). Even the least
expensive printer provides sufficient resolution for most
range of quality and prices, The normal computer speakers purposes at 600 dpi
are small, plastic, and have mediocre sound quality. Other
Speed Speed means number of pages that are printed in
speakers are available that have equalization features
one minute. The speed of a printer is an important factor
such as bass and treble controls. Users can also use a lead
for users who have a large number of pages to print, While
to connect their computer's sound output to an existing
high-speed printers are quite expensive, the inexpensive
stereo system to give much better results than the small,
printers, on the other hand, can print only about 3-6 sheets
low-cost computer speakers.
per minute. Colour printing is even slower

2.2.2 Hard Copy Devices Memory Most printers have a small amount of memory
(for example, | MB), which can be expanded by the user.
Hard copy output devices are those that produce a physical
Having more memory enhances the speed of printing.
form of output. For example, the content of a file printed
Printers can be broadly classified into two groups:
on paper is a form of hard copy output. The features of
impact and non-impact printers as shown in Figure 2.23.
hard copy output include
* Acomputer is not needed to sce the output Impact Printer
Editing and incorporating the edits in the hard copy is These printers print characters by striking an inked ribbon
difficult against the paper. Examples of impact printers include dot
* Hard copy output can be easily distributed to people matrix printers, daisy wheel printers, and most types of
who do not have a computer line printers
* Searching for data in a hard copy is a tiring and difficult
job. Advantages
* Distribution of hard copy is not only costly but slower * These printers enable the user to produce carbon copies.
as well * They are cheap.
Disadvantages
Printers + Impact printers are slow
A printer is a device that takes the text and graphics * They offer poor print quality, especially in the case of
information obtained from a computer and prints it on graphics.
a paper, Printers are available in the market in various * They can be extremely noisy
sizes, speeds, sophistication, and costs, Usually, more * They can print only using the standard font
expensive printers are used for higher-resolution colour
printing. The qualities of printers that are of interest to Non-impact printer
users include
Non-impact printers are much quieter than impact printers,
Colour Colour printouts are needed for presentations, as their printing heads do not strike the paper. They offer
maps, and other pages where colour is part of the better print quality, faster printing, and the ability to create

Impact printers

Dot matrix Daisy wheel Line Inkjet

Figure 2.23 Classification of printers


34 Computer Fundamentals and Programming in C

Prints that contain sophisticated graphics. Non-impact The speed of dot matrix printers varies in the range of
printers use cither solid or liquid cartridge-based ink, 50-500 cps (characters per second).
which is cither sprayed, dripped,orclectrostatically drawn
Advantages
onto the page. The main types of non-impact printers are
* The dot matrix printer can produce carbon copies.
inkjet, laser, and thermal printers.
* It offers the lowest printing cost per page.
Advantages * It is widely used for bulk printing where the quality of
* Non-impact printers produce prints of good quality, and the print is not of much importance.
hence render sophisticated graphics. + Itis inexpensive
re noiseless. * When the ink is about to be exhausted, the printout
re fast gradually fades rather than suddenly stopping partway
* They can print text in different fonts. through a job.
Disadvantages * Itcan use continuous paper rather than individual sheets,
+ These printers are expensive making them useful for data logging.
* The ink cartridges used by them are also costly Disadvantages
In this section, we will read about the different types of + This type of printer creates a lot of noise when the pins
the printers. strike the ribbon against the paper.
* Itcan only print lower resolution graphics, with limited
Dot matrix printer A dot matrix printer (shown in
quality
Figure 2.24) prints characters and images of all types
* Itis very slow
as a pattern of dots (hence the name). This printer has a
printhead (or hammer) that consists of pins representing * It has poor print quality
the character or image. The printhead runs back and forth, Daisy wheel printer Daisy wheel printers use an impact
or in an up-and-down motion on the page and prints by printing technology to generate high quality output
striking an ink-soaked cloth ribbon against the paper, comparable to typewriters, and are three times ter
much like the print mechanism of a typewriter However, today, daisy wheel technology is found only in
some electronic typewriters,
The printhead of a daisy wheel printer is a circular
wheel, about 3 inches in diameter with arms or spokes.
The shape of the printer wheel resembles the petals of
a daisy flower, and hence its name. The characters are
embossed at the outer ends of the arms.
To print a character, the wheel is rotated in such a way
that the character to be printed is positioned just in front
of the printer ribbon. The spoke containing the required
character is then hit by a hammer, thereby striking the
ribbon to leave an impression on the paper placed behind
the ribbon. The movement of all these parts is controlled
Figure 2.24 Dot matrix printer
by a microprocessor in the printer.
The key benefit of using a daisy wheel printer is that
Source: burnel1/Shutterstock the print quality is high, as the exact shape of the character
hits the ribbon to leave an impression on the paper.
From the 1970s to 1990s, dot matrix impact printers
were the most common type of printers used with PCs. Line printer A line printer is a high-speed impact printer
Several dot matrix printer manufacturers implemented in which one typed line is printed at a time. The speed
colour printing through a multi-colour ribbon. Colour was of a line printer usually varies from 600 to 1200 lines
obtained through a multi-pass composite printing process per minute, or approximately 10-20 pages per minute.
In cach pass, the printhead struck a different section of the Because of their high speed, line printers are widely
ribbon (one primary colour), However, because of poor used in data centers and in industrial environments, Band
colour quality and increased operating expense, colour printer is a commonly used variant of line printers.
dot matrix printers could never replace their monochrome
counterparts, Moreover, the black ink section would Band printer A band printer (loop printer), is an impact
gradually contaminate the other three colours (RGB), printer with a printing mechanism that uses a metal loop
thereby changing the consistency of printouts over the life or band to produce typed characters, The set of characters
of the ribbon. The colour dot matrix printer was therefore are permanently embossed on the band, and this set cannot
suitable only for abstract illustrations and pie charts, but be changed unless the band is replaced. The band itself
not for photo-realistic reproduction revolves around hammers that push the paper against the
Input and Output Devices &

ribbon, allowing the desired character to be produced on inkjet printers have to be changed more frequently,
the paper. the special coated paper required to produce high quality
The main advantage of using a band printer is its output is very expensive. Hence, the cost per page of
high speed. This type of printer can print 2000 lines per inkjet printers becomes ten times more than laser printers.
minute, and is, therefore. perfect for high volume printing Therefore, inkjet printers are not well suited for high
in businesses, schools, and other organizations. Band volume print jobs.
printers are normally attached to mainframes and used for Laser printer A laser printer, shown in Figure 2.26,
industrial printing.
is a non-impact printer that works at very high speeds
However, band printers cannot be used for any graphics and produces high-quality text and graphics. It uses
printing, as the characters are predetermined and cannot the technology used in photocopier machines. When a
be changed unless the band is changed. Band printers were
document is sent to the printer, the following steps take
very popular in the 1970s and 1980s; however, today, laser place:
printers have replaced band printers.
+ A laser beam ‘draws’ the document on a drum (which
is coated with a photo-conductive material) using
electrical charges.
Band printers are often confused with band printing. * After the drum is charged, it is rolled in a toner (a dry
Band printing istheprocess ofsending output toa powder type of ink).
printer and isnot associated with this type ofprinters. * The toner sticks to the charged image on the drum,
* The toner is transferred onto a piece of paper and fused
Inkjet printer Inkjct printers, shown in Figure 2.25, came to the paper with heat and pressure.
in the market in the 1980s, but it was only in the 1990s that * After the document is printed, the electrical charge is
their prices reduced enough to bring the technology to the removed from the drum and the excess toner is collected.
high street. Inkjet printers have made rapid technological
advances in recent years. The colour inkjet printers have
succeeded in making colour printing an affordable option
even for home users.

Figure 2.26 Laser printer


Source: restyler/Shutterstock
Figure 2.25 Inkjet printer
Source: lakov Filimonov/Shutterstock While colour laser printers are also available in the
market, users mostly prefer monochrome printers, because
The printhead of inkjet printers has several tiny nozzles, the former is up to ten times more expensive than the latter.
also called jets. As the paper moves past the printhead, the
nozzles spray ink onto it, forming characters and images. Plotters
If you observe a printout that has just come out from an
inkjet printer, you will see that the dots are extremely A plotter as shown Fig. 2.27 is a printing device that is
small (usually between 50 and 60 microns in diameter) usually used to print vector graphics with high print
and are positioned very precisely, with resolutions of up to quality. They are widely used to draw maps, in scientific
1440 x 720 dpi. To create a coloured image, the dots can applications, and computer-aided engineering (CAE).
have different colours combined together. Architects use plotters to draw blueprints of the structures
An inkjet printer can produce from 100 to several they are working on.
hundred pages (depending on the nature of the hard copy), A plotter is basically a printer that interprets commands
betore the ink cartridges must be replaced. There is usually from a computer to make line drawings on paper with one
one black ink cartridge and one colour cartridge containing or more automated pens. Since plotters are much more
ink in primary pigments (cyan, magenta, and yellow). expensive than printers, they are used only for specialized
While inkjet printers are cheaper than laser printers, applications. There are two different types of plotters,
they are more expensive to maintain. The cartridges of drum and flatbed.
36 Computer Fundamentals and Programming in C

is mounted on a carriage, is moved across the width of the


paper. Hence, the vertical movement of the paper and the
horizontal movement of the pen create the required design
under the control of the computer.
Drum plotters can make multicolour drawings by using
pens with different coloured inks. Moreover, drum plotters
support very large plot sizes with paper widths of up to
1 meter,

Flatbed plotter In a flatbed plotter, the paper is spread


on the flat rectangulur surface of the plotter, and the pen
is moved over it. Flatbed plotters are less expensive, and
are used in many small computing systems, The size of
the plot is limited only by the size of the plotter's bed
Figure 2.27 Plotter In this type of plotter, the paper does not move; rather,
Source: Michal Vitek/Shutterstock plotting is done by moving an arm that moves a pen over
the paper.
Drum plotter A drum plotter is used to draw graphics In case of a flatbed plotier, pens of different colours
on paper that is wrapped around a drum. This type of are mounted in the pen-holding mechanism that moves on
plotter is usually used with mainframe and minicomputer te surface. The microprocessor in the plotter selects the
systems, The drum plotter works by rotating the drum desired pen and controls its movement under the control
back and forth to produce vertical motion, The pen, which of the computer.

POINTS TO REMEMBER
* An input device is used to feed data and instructions The sound card is a hardware unit that converts
into the computer. analog signals generated through the microphone
© Keyboard is an electro-mechanical device, which is into digital data, so that it can be stored in the
used to input alphanumeric data into the computer. computer.
A pointing input device enables the users to easily Video input devices are used to capture video from
control the movement of the pointer, It is connected the outside world into the computer.
to the serial or USB port on the system unit. * Any device that outputs/gives information from a
Mouse is an input device, which enable users to control computer can be called an output device, Basically,
the movement of the pointer in graphical user interface output devices are electromechanical devices that
A joystick is a cursor control device widely used in accept digital data from the computer and convert
computer games and CAD/CAM applications. them into human understandable language.
A stylus is a pen-shaped input device used to enter * The monitor is a soft copy output device used to
information or write on the touchscreen of a phone. display video and graphics information generated by
A touchscreen is a display screen that can identify the the computer through the video card. It is connected
occurrence and position of a touch inside the display to either the VGA or the DVI port on the video card
region. (which is on the motherboard or separately
A barcode reader is a handheld input device used to purchased).
capture and read information stored in a barcode. A projector is a device that takes an image from a
A scanner is a device that captures images, printed video source and projects it on a screen or another
text, and handwriting, from different sources such as surface,
photographic prints, posters, and magazines, and * Dot matrix printer is an impact printer, which prints
converts them into digital images for editing and characters and images as a pattern of dots.
display on computers. * Laser printer is a non-impact printer, which uses a
© Audio devices are used to either capture or create laser beam to produce an image on a negatively-
sound, Microphones and CD players are examples of charged cylindrical drum.
two widely used audio devices.
Input and Output Devices 37

GLOSSARY
impact printer A printer that works by striking an inked extracting data from marked fields, such as checkboxes
ribbon against the paper and fill-in fields, on printed forms
Input device A device that is used to feed data and Outputdevice Adevice
thatisused to present information
instructions into the computer from the computer to the user
Optical character recognition The process of converting Pointing device A device that enables the users to easily
printed materials into text or word processing files that control the movement of the pointer to select items on
can be easily edited and stored a display screen, to select commands from the command
Optical device A device that uses light as a source of input menu, to draw graphics, etc
for detecting or recognizing different objects Printer Adevice that takes the text and graphics information
Optical mark recognition The process of electronically obtained from a computer and prints it on paper

EXERCISES
Fill in the Blanks 3. Select the printer that uses impact printer technology
1, _____ is used to feed data and instructions into the from the following options
computer. (a) Daisy wheel (b) Laser
2 captures everything on the screen as an {c) Band (d) Inkjet
image. 4. Select the pointing devices from the following options:
3, The movement of an optical mouse is detected using
(a) Keyboard (b) Barcode reader
ae WAVES,
{c) Joystick (d) Touchscreen
4, ___ is used to enter information or write on the
5. Which type of screen is used in gaming devices, clocks,
touchscreen of a phone.
watches, calculators, and telephones?
5. A barcode reader is connected to the computer through
aL port. (a) LCD (b) Plasma
6 sttechnology is used for electronically extracting ({c) CRT (d) All of these
data from marked fields.
7. ____ converts analog signals generated through a State True or False
microphone into digital data 1, Home and End keys move the cursor to the previous and
8, ______s capture videos that can be transferred via the next page, respectively.
Internet in real-time 2. Pointing devices can be connected to the USB port of a
9. allow the users to talk and listen at the same computer.
time. 3, The movement of the cordless mouse is detected using
10, The resolution of a printer means laser technology.
4. OCR is used to verify the legitimacy or originality of
Multiple-choice Questions paper documents.
1, Which keys are used by applications and operating 5. The monitor is a soft copy output device.
systems to perform specific commands? 6. Non-impact printers create characters by striking an
(a) Typing keys (b) Arrow keys inked ribbon against the paper.
7. A laser printer uses the same technology used in
() Control keys (d) Function keys
photocopier machines.
2, Select the optical devices from the following options
8. A plotter is used to print vector graphics
(a) MICR (b) Barcode reader
9. A mouse cannot be used with a laptop computer.
(c) Scanner (d) All of these
38 ‘Computer Fundamentals and Programming in C

10, Soft copy output devices are those that produce a 11 Under which situation, will you prefer to use an inkjet
physical form of output. printer over a laser printer?
12 How is a plotter different from a printer?
Review Questions 13. Explain the variants of plotters.
1, How does a keyboard work? 14 What are input devices? Discuss the different types of
2. Explain the working of different types of mouse. input devices in detail.
3, How is OCR technology better than an ordinary image 15. Give a detailed note on different output devices.
scanner? 16. How is a touchpad better than a trackball?
4, How does MICR technology help to detect fraud in 17, Which pointing input device would you prefer to use,
cheque payments? mouse or trackball? Justify your answer.
5, Web cameras can be used to check security in a bank 18. List the applications of touchscreen
Comment 19. What are optical input devices? Where are they used
6. How are projectors used to display information to a and for what purpose?
user? 20, Differentiate between a soft copy and a hard copy
7. How are headsets better than speakers and headphones? output
8. Differentiate between impact and non-impact printers. 21 Which factors will you consider while purchasing a
9. Can characters of different fonts be printed with a band monitor for your personal computer? After considering
printer? the factors, which monitor will you buy?
10. Why is a line printer preferred over a dot matrix printer? 22 What is a data projector? How is it different from a
if you have an image to be printed, which out of the two computer screen?
will you use and why?
Computer Memory and
“Processors
TAKEAWAYS
* Sequential access © Magnetic tapes * Memory cards
* Random access © Floppy disks © Mass storage devices
* Processor registers © Hard disks * Processor architecture
* Cache memory © Optical drives * Pipelining
© Primary memory © USB flash drives * Parallel processing
* Secondary memory

€X9 intrRopuction Differences between sequential and


random access
Memory is an internal storage area in the computer, Sequential access [Random access
which is used to store data and programs either Data isread sequentially
ina Data is read in an arbitrary
temporarily or permanently. Computer memory can spocitiod order. manner,
be broadly divided into two groups—primary memory
and secondary memory. While the main memory holds
instructions and data when a program is executing, Ifthe 99th record isdesired Random access always
the auxiliary or the secondary memory holds data and after the Ist one, then allthe returns data in constant time,
programs that are not currently in use and provides records have tobe traversed
long-term storage to reach the desired one,
To execute a program, all the instructions or data Therefore, the time required to
that has to be used by the CPU has to be loaded into return data can vary depending
the main memory. However, the primary memory is on the position ofthe record.
volatile and so it can retain data only when the power is Sequential access devices can Random access devices are
on, Moreover, it is very expensive and therefore limited store a large number of records expensive than sequential
in capacity ata very low cost. access devices,
On the contrary, the secondary memory stores data Magnetic
tapes support RAM (Random Access
or instructions permanently, even when the power sequential access. Memory) supports random
is turned off. It is cheap and can store large volumes access,
of data, Moreover, data stored in auxiliary memory is Sequential-access is faster if Random-access is faster if
records are tobe accessed inthe records are to be accessed in a
highly portable, as the users can easily move it from one
same order. random order.
computer to another. The only drawback of secondary
memory is that data can be accessed from it at very low
speeds as compared with the data access speed of the
primary memory if the need of application is to access all the records in
order then sequential
access isbetter.
2 SEQUENTIAL AND RANDOM ACCESS
XE) memory HIERARCHY
Memory devices can be accessed cither randomly or
sequentially, The method of access has a great impact on In contemporary usage, memory usually refers to
application efficiency in terms of disk usage, Therefore,we random access memory (RAM), typically dynamic
must understand the differences between these two access RAM (DRAM), but it can also refer to other forms of
methods which are listed in Table 3.1 data storage. In computer terminology, the term storage
40 Computer Fundamentals and Programming in C

féfers to storage devices that are not directly accessible


by the CPU (secondary or tertiary storage). Examples of 9 cAcHE MEMORY
secondary storage include hard disk drives, optical disk
drives, and other devices that are slower than RAM but are Cache memory is an intermediate form of storage between
used to store data permanently the ultra-fast registers and the RAM. The CPU uses cache
These days, computers use different types of memory, memory to store instructions and data that are repeatedly
which can be organized in the hierarchy as shown (Figure required to execute programs, thereby improving the
3.1). As we can sce from the figure, there is a trade-off overall system speed and increasing the performance of
between performance and cost. The memory at the higher the computer. Maintaining frequently accessed data and
levels in the storage hierarchy has less capacity to store instructions in the cache helps in avoiding the need to
data, is more expensive, and is faster to access. access the slower DRAM repeatedly
Cache memory is widely used for memory caching.
Cache memory is a portion of memory made of high speed
static RAM (SRAM) instead of the slower and cheaper
(C)system’s memory DRAM which is used for main memory
CPU registers
Some memory caches are in-built in the architecture
of microprocessors. For example, the Intel 80486
«© Less access time microprocessor has an SK memory cache, and the Pentium
Level I cache £2160 has a 1 MB cache, Such internal caches are often
= = * Smaller in size called level 1 (L1) caches. However, modern PCs also
come with extemal cache memory, called level 2 (L2)
* Le a c it) caches, which are built into the motherboard outside the
Level 2 cache i ia CPU. Although L2 caches are composed of SRAM, they
= oo * Stores data till the power is on are much larger in size than L1! caches, Another type of
cache, called level 3 (L3), which is not normally used, is
Level 3 cache an extra cache that has a much larger size than L1 and L2
caches, but is slower than them (but faster than RAM).

Working of the Cache Memory


Primary memory
When a program is being executed and the CPU wants to
read data or instructions, the following steps are performed.
* Less expensive The CPU first checks whether the data or instruction is
available in the cache memory, If it is not present there, the
* More access time CPU reads the data or instructions from the main memory
into the processor registers and also copies it into the
* Bigger
insize cache memory, When the same piece of data/instruction
is needed again, the CPU reads it from the cache memory
* More capacity
instead of the main memory.
* Stores data even when the
power is not on 83 primary Memory
Primary memory (or main memory or internal memory)
[[]system’s memory [J] Ontine [Ii] Near tine [I omine can be directly accessedby the CPU. The CPU continuously
reads instructions stored in the primary memory and
Figure 3.1 Memory hierarchy executes them. Any data that has to be operated by the
CPU is also stored there.
Historically, early computers used delay lines, William's
EXD PROCESSOR REGISTERS tubes, or rotating magnetic drums as primary storage.
From 1954 to 1970s, magnetic core memory became the
Processor registers are located inside the processor and dominant technology to be used as the primary memory
are therefore direct sed by the CPU. Each register of computers. Later, in the 1970s, magnetic core memory
stores a word of data (which is either 32 or 64 bits). CPU was replaced by semiconductor memory that used a large
instructions instruct the arithmetic and logic unit (ALU) number of integrated circuits. This led to the development
to perform various calculations or other operations on this of the modern RAM.
data. Registers are the fastest among all types of computer However, there is another type of primary memory
data storage. called read-only memory (ROM), which is non-volatile
Computer Memory and Processors | 41

in nature. In this section, we will read about the different while reading a bit, the transistor checks for a charge if
types of RAM and ROM available in the market the capacitor. Ifacharge is present, then the reading is 1;
if not, the reading is 0.
3.6.1 Random Access Memory (RAM) However, the problem with DRAM is that the capacitor
leaks energy very quickly and can hold the charge for
RAM is a volatile storage area within the computer that only a fraction of a second. Therefore, a refresh process
is typically used to store data temporarily, so that it can is required to maintain the charge in the capacitor so that
be promptly accessed by the processor. The information it can retain the information. This refreshing process is
stored in the RAM is basically loaded from the computer's carried out multiple times in a second and requires that all
hard disk, and includes data related to the operating cells be accessed, even if the information is not needed.
system and applications that are currently being executed However, the advantage of DRAM over SRAM is that
by the processor. it is cheap, can hold more data per chip, and generates less
RAM is considered random access because any memory heat than SRAM. DRAM is widely used to build the main
cell can be directly accessed if its address is known. When memory. The following are the different types of DRAM:
the RAM gets full, the computer system operates at a slow
Synchronous DRAM (SDRAM) SDRAM synchronizes
speed. When multiple applications are being cxecuted
itself with the clock speed of the microprocessor to enable
simultaneously and the RAM gets fully occupied by
faster access lo memory
the application's data, it is searched to identify memory
portions that have not been utilized. The contents of those Enhanced SDRAM (ESDRAM) This version of SDRAM,
locations are then copied onto the hard drive. This action though not widely used, includes a small SRAM cache to
frees up RAM space and enables the system to load other reduce delays in data access and speed up operations,
pieces of required data. Double data rate SDRAM (DDR) DDR allows data
These the applications’ and operating system's transfers on both the rising and falling edges of the clock
demand for system RAM has drastically increased. For cycle, which doubles the data throughput, DDR SDRAM
example, in the year 2000, a personal computer (PC) had chips are available in capacities of 128MB to 1GB
only 128 MB of RAM, but today PCs have 1-2 GB of RAM Although DDR memory is very common, the technology
installed, and may include graphics cards with their own is becoming outdated and is being replaced by DDR2,
additional $12 MB or more of RAM. As discussed carlicr,
there are two types of RAM—static RAM (SRAM) and DOR2 These chips are the next generationofDDR SDRAM
dynamic RAM (DRAM). memory. It can hold 256 MB to 2GB of memory and can
Operate at higher bus speeds. Although DDR2 has twice
StaticRAM This is a type of RAM that holds data without the latency (data access delays) of DDR, it delivers data at
an external refresh as long as it is powered. This is in twice the speed, thereby performing at the same level.
striking contrast with the DRAM which must be refreshed
multiple times in a second to hold its data contents. SRAM Rambus DRAM (RDRAM) It is a proprietary, protocol-
is made of D flip-flops in which the memory cells flip-flop based, high-speed memory technology developed by
between 0 and | without the use of capacitors. Therefore, Rambus Inc. RDRAM can operate at extremely high
there is no need for an extemal refresh process to be frequencies as compared to other types of DRAMs.
carried out Synchronous link dynamic RAM (SLDRAM) This version
The limitation of SRAM is that it occupies more space of SDRAM, not used widely, was basically designed as a
and is more expensive than DRAM, While each transistor on royalty-free, open-industry standard design alternative to
a DRAM chip can store one bit of information, the SRAM RDRAM
chip, on the other hand, requires four to six transistors to
store a bit, This means that a DRAM chip can hold at least 3.6.2 Read-only Memory (ROM)
four times as much data as an SRAM chip of the same size,
thereby making SRAM much more expensive. ROM refers to computer memory chips containing
permanent or semi-permanent data. Unlike RAM, ROM is
However, SRAM is faster, more reliable than DRAM,
non-volatile; that is, the data is retained in it even after the
and is often used as cache memory. SRAM chips are
also used in . houschold appliances, and handheld computer is tumed off.
Most computers store critical programs like the basic
electronic devices.
inpuVoutput system (BIOS) in ROM, which is used to boot
Dynamic RAM This is the most common type of memory up the computer when it is tumed on. The BIOS consists
used in personal computers, workstations, and servers of a few kilobytes of code that tells the computer what to
today. A DRAM chip contains millions of tiny memory do when it starts up, such as running hardware diagnostics
cells. Each cell is made up of a transistor and a capacitor, and loading the operating system into the RAM, Morcover,
and can contain | bit of information—0 or 1. To store ROMs are used extensively in calculators and peripheral
a bit of information in a DRAM chip, a tiny amount of devices such as laser printers, whose fonts are often stored
power is put into the cell to charge the capacitor. Hence, in ROMs.
42 Computer Fundamentals and Programming in C

Originally, ROMs were read-only. So, in order to 3.6.3 Finding Required Data from Main
update the programs stored in them, the ROM chip had to
Memory
be removed and physically replaced by another that had
4 newer version of the program. However, today ROM The main memory is organized as a matrix of bits, as
chips are not literally read-only, as updates to the chip shown in Figure 3.2. A matrix of bits means a combination
are possible. The process of updating a ROM chip is a of rows and columns that stores a bit. The main memory,
bit slower, as memory must be erased in large portions which holds the user’s data and programs for execution by
before it can be rewritten. Rewritable ROM chips include the CPU, is directly or
PROMs, EPROMs, and EEPROMs. indirectly connected to
the processor via a bus
Programmable read-only memory (PROM) It is also
called one-time programmable ROM, and can be written
There are two buses, an
to or programmed using a special device called a PROM address bus and a data
bus. The CPU first sends
programmer. The PROM programmer uses high voltages
a number through the
to permanently destroy or create internal links (fuses or
address bus,
anti-fuses) within the chip. The working of a PROM is
similar to that of a CD-ROM recorder, which enables the This number denotes
the memory address
users to burn programs onto blank CDs, The recorded
or the burnt data can be read multiple times. Therefore, of the desired location
programming a PROM is also called burning, just like
of data. Then it reads
burning a CD-R, and is comparable in terms of its
or writes the data itself
using the data bus. Figure 3.2 Bit matrix
flexibility.
Erasable programmable read-only memory (EPROM) It
is a type of ROM that can be erased and re-programmed. ED SECONDARY STORAGE DEVICES
The EPROM can be crased by exposing the chip to strong
ultraviolet light, typically for 10 minutes or longer, and Secondary storage (also known as external memory or
can then be rewritten with a process that again needs the auxiliary storage) differs from main memory in that it is
application of a higher voltage. Repeated exposure to not directly accessible by the CPU. The secondary storage
ultraviolet light wears out the chip. The EPROM is much devices hold data even when the computer is switched off.
more useful than PROM and can be compared with a An example of such a device is the hard disk.
reusable CD-RW. The computer usually uses its input/output channels to
Electrically erasable programmable read-only memory access data from the secondary storage devices to transfer
(EEPROM) Itis based on a semiconductor structure similar the data to an intermediate area in the main memory.
to the EPROM, but allows the entire or selected contents Secondary storage devices are non-volatile in nature,
to be electrically crased, then rewritten electrically, so that cheaper than the primary memory, and thus can be used
they need not be removed from the computer (or camera, to store huge amounts of data, While the CPU can read
MP3 player, ctc,). The process of writing an EEPROM is the data stored in the main memory in nanoseconds, the
also known as flashing. data from the secondary storage devices can be accessed
The flash memory is also a type of EEPROM in which in milliseconds.
the contents can be erased under software control. This is The secondary storage devices are basically formatted
the most flexible type of ROM, and is widely used to store according to a file system that organizes the data into files
BIOS programs. It is primarily used in memory cards, and directories. The file system also provides additional
USB flash drives, MP3 players, personal digital assistants information to describe the owner of a certain file, the
(PDAs), laptop computers, digital audio players, digital access lime, the access permissions, and other information.
cameras, and mobile phones. The EEPROM blurs the
difference between read only and read—write. However, the 3.7.1 Offline Storage
EEPROM is rewritten only once a year or so, compared to
Offline storage devices are those on which data is
real read-write memory (RAM), where rewriting is often
recorded and then physically removed or disconnected
done many times per second.
(off the computer, hence the name). Such devices include
magnetic tapes, floppy disks, optical disks, flash memory
devices, and external hard disks, In order to access data
(a) By applying write protection,
some types of from an offline storage device, it must first be connected
reprogrammable ROMs may temporarily become to a computer.
read only memory. Offline storage devices are widely used to store a
(b) In practice, both RAM and ROM support random backup of important data. For example, if the original
access of memory. data gets destroyed in case of a disaster, the data can be
Computer Memory and Processors 43

recovered from the offline devices, which are usually ofasupply reel, a take-up reel, a R/W head, and an eras€
stored in another distant place. Moreover, offline storage head. When the user has to edit/rewrite the pre-recorded
also provides security of critical data, as these devices are data on a tape, the previously recorded data is erased by
physically inaccessible by a computer, and therefore data the erase head and the new data is recorded. The process
confidentiality or integrity cannot be affected by malicious of recording data is much similar to that of recording on an
software. audio tape or audio cassette
Usage A magnetic tape can store large amounts of
EX) macnetic tapes information and is therefore used in the regular backing
up of hard disks.
Magnetic tapes (shown in
Figure 3.3) are mass storage Advantages
devices capable of backing * Amagnetic tape is compact in size, light in weight, and
up and = retaining =large can store large amounts of data. Therefore, tapes are
volumes of data. A magnetic
easily portable and can be used to transfer data from
tape, which resembles an one computer to another.
audio tape, is a thin stnp of Magnetic tapes are economical. The cost of storing
plastic coated with magnetic characters is very less as compared to other storage
recording material, These
devices.
storage devices are basically
Copying of data on a magnetic tape is easy and fast
used as sequential ac Magnetic tapes can be used for long-term data storage
Figure 3.3 Magnetictape secondary storage devices. and retrieval
Magnetic tapes are available in the form of cassettes, * Tape drives use less power.
reels, and cartridges, with recls being most widely used.
* Tape drives can easily be stored offsite, allowing data
Reels that are used with mini and mainframe computers are to survive even if the computer itself is destroyed or
1/2 inch wide and 2400 feet long. Such a tape can store stolen.
1600 characters per inch of the tape length. This means that
about 50 books could be stored on just one reel of tape.
Disadvantages
Storage capacity of magnetic tape
Data recording density * Length of the tape * Data stored
on the tape can be accessed only sequentially.
* As compared to other storage devices, data on a tape is
Here, data recording density is the amount of data that
accessed at very slow speeds because of serial access,
can be stored on a given length of tape. It is measured * Special hardware is required to read the data stored on
in bytes per inch (bpi), and usually varies from 800 to
tapes, and most standard PCs available today do not
77,000 bpi. For example, a tape of length 2400 feet with come with such hardware.
1000 bpi as its storage density has a storage capacity of + With advancements in technology, hard drives are
2400 * 12 * 1000 = 2,88,00,000 = 28 « 10° =28MB. becoming cheaper than tapes and are therefore being
However, as of now, magnetic tapes with stora: increasingly used for backups.
capacity of up to 35 trillion bytes (terabytes) of data are
Magnetic tapes are casily susceptible to degradation due
easily available in the market to heat, humidity, dust, mishandling, electromagnetic
Data representation On a magnetic tape, data is recorded surfaces, and ordinary wear.
in the form of tiny non-magnetized and magnetized spots, * Magnetic tapes are best suited for full-system restores
where the presence of a spot represents | and its absence and not for restoring of individual files. This is because
represents 0. This means that data is stored in the form of finding and restoring individual files can be a long,
0s and 1s. For example, ‘A’ is stored as 1011 on the tape. slow, and cumbersome process,
Data on a tape is represented using the EBCDIC standard.
However, the data stored on a tape can be accessed only in
a sequential fashion, Unlike magnetic disks, flash drive
EX) Fiopry pisks
optical drives, and floppy drives, magnetic tapes do not Floppy disks (shown in Figure 3.4) are data storage devices
support random access of data.
that consist of a thin magnetic storage medium encased in
On a tape, the data is stored in terms of records, with
a square plastic shell lined with fabric that removes dust
individual records separated by a gap known as the inter- particles. The storage capacity of floppy disks is very
record gap. \n addition, when records are short, they may
limited as compared to CDs and flash drives, Although
be grouped to form blocks. The data stored in the form of
floppy drives are very cheap, they are much slower than
blocks will then have inter-block spacing other data storage devices. Moreover, floppy disks must be
Magnetic tape drive A tape drive is used to read and handled with utmost care as they are vulnerable to damage
write data on a magnetic tape. The tape drive units consist from mishandling. For example, data stored on a floppy disk
44 Computer Fundamentals and Programming in C

can be lost if the disk padding bytes are written on these, which are discarded by
is bended, removed the floppy disk controller.
while in use, or Moreover, each data sector has a header that stores the
exposed to excessive sector location on the disk. An error checking code is also
temperature, dust, or written into the sector headers and at the end of the user
smoke. data, so that the diskette controller can detect errors when
Floppy disks were reading the data.
widely used from the
Storage capacity All 3.5 inch floppy disks are double-
mid-1970s till 2000
sided. They have 80 sectors, 18 sectors/track, and can
to distribute software,
store 512 bytes/sector.
transfer data, and
create backups. Today, Therefore the storage capacity of afloppy disk
Figure 3.4 Floppy disk however, their use has 2 *« 80 * 18 © 512 bytes
become very limited 14,74,560 bytes = 147 MB
Source: Photodisc/OUP Picture Bank
as they have been
superseded by
drives, external hard drives, optical disks, and memory cards.
flash
ERT Hard visks
The mechanism of a floppy disk involves two motors.
While one motor in the drive rotates the diskette at a The hard drive is a part of the computer that stores all the
programs and files, so if the drive is damaged for some
regulated speed, the second motor moves the magnetic
reason, all the data stored on the computer is lost. The hard
R/W head (or heads, if a double-sided drive) along the
disk provides relatively quick access to large amounts of
surface of the disk. To read/write data on the disk media,
data stored on an clectromagnetically charged surface or a
there must be physical contact between the R/W head and
set of surfaces. Today, PCs come with hard disks that can
the disk media. Figure 3.5 shows the internal parts of a
store gigabytes of data.
floppy disk.
A hard disk is basically a set of disks, stacked
Reading/Writing data In order to write data on a floppy together like phonograph records, that has data recorded
disk, current is passed through a coil in the head. The electromagnetically in concentric circles known as
magnetic field of the coil magnetizes spots on the disk tracks
as it rotates. The change in magnetization encodes the A single hard disk includes several platters (or disks)
digital data, that are covered with a magnetic recording medium.
Similarly, to read data from the floppy disk, a small Each platter requires two read/write (R/W) heads, one for
amount of current is induced in the head coil to detect each side. Note that in the figure, all the R/W heads are
the magnetization on the disk. The floppy drive controller attached to a single access arm and so they cannot move
separates the data from the stream of pulses coming from independently. The parts of the hard disk are shown in
the floppy drive, decodes the data, tests for errors, and Figure 3.6,
sends the data on to the host computer system.
Tracks and sectors A blank floppy disk has a pattem of Rw
magnetized tracks, cach broken into sectors. The tracks Arm head Sector
on the floppy drive have some spaces between the tracks Spindle
where no data is written, Similarly, there are spaces Track
between the sectors and at the end of the track to allow Platter
for slight speed variations in the disk drive. Usually some [ff

Cylinder
Shell/Housing b 0&
Magnetic disk (
Shell/Housing
k)Nt fh
Af 0
a aA
SE So

Paper ring
Figure 3.5 Components of a floppy disk Figure 3.6 Schematic diagram of a hard disk
Computer Memory and Processors 45

The R/W head can pivot back and forth over the platters disk drive makes it susceptible to head crash. Head crash
to read or write data on them. Data is actually stored on the can also occur if dust settles into the hard drive, thereby
surface of a platter in sectors and tracks (refer Figure 3.7). resulting in bouncing of the arm when the disk operates.
While the tracks are concentric, sectors on the other hand During a head crash, the fragile magnetic recording medium
are pic-shaped wedges on a track. Thus, a track is divided gets ruined, resulting in loss of the data stored in it. Laptop
into a number of segments (also called sectors) that can users must very carefully move their laptops as moving it
store a fixed number of bytes—for example, 256 or 512 abruptly when it is switched on can lead to head crash.
The tracks are numbered consecutively from outermost to The performance of a hard disk depends on its access
innermost, starting from zero, The number of tracks on time, which is the time required to read or write on the
a disk can vary from 40 on some low capacity disks to disk. Access time is a combination of the following three
several thousands on high capacity disks components:
Seek time This is the time taken to position the R/W head
A sector over the appropriate cylinder (usually around 8 ms on an
average). Seck time varies depending on the position of
the access arm when the R/W command is received. Its
value will be maximum when the access arm is positioned
over the innermost track while the data that has to be
accessed is stored on the outermost track. Similarly, it will
be zero if the access arm is already positioned over the
desired track. On an average, the seck time varies from 10
to 100 milliseconds.
a a A track Rotational delay This is the time taken fo bring the target
sector to rotate under the R/W head. Assuming that the
Figure 3.7 Cross-section of a cylinder hard disk has 7200 rpm, or 120 rotations per second, a
single rotation is done in approximately 8 ms. The average
Moreover, cach platter has the same number of tracks, rotational delay is around 4 ms.
and a track location that cuts across all platters is
called a cylinder. In simple terminology, a cylinder is Transfer time The time to transfer data or read/write to a
vertically formed by tracks. For example, track 2 on disk is called the transfer rate.
platter 0 plus track 2 on platter 1, plus track 2 on platter Thus, the overall time required to access data = seck
n is cylinder 2. The number of cylinders of a disk drive time + rotational delay + transfer time.
is equal to the number of tracks on a single platter of The sum of the seck time and the rotational delay is
the disk also known as disk latency. Disk latency is the time taken
When the computer is turned on, the platters in the hard to initiate a transfer.
disk drive immediately begin to spin. While the platters
in a desktop computer hard disk drive rotate 7200 times
per minute, on the other hand, the hard drives in laptop
The key tousing the hard drive effectively is to
computers usually make $400 rotations per minute (rpm).
minimize
disklatency. Ideally,
thiscan bedone by
You must have heard the steady hum of your hard drive.
defragmentation, which moves related data to physically
Even when you are not retrieving from or writing anything
proximate areas on the disk. Some computer operating
to the hard disk, the platters spin. However, the arm with
systems perform defragmentation automatically,
the R/W head moves only when you run 4 program or
open, save, or delete a file, The arm can move back and
forth across the surface of the platter as many as 50 times To access data from a hard disk, a disk address has to be
in a second. specified. The disk address represents the physical location
of a record on the disk, and comprises the following
components:
* Sector number
Atypical hard disk drive has two electric motors—a disk * Track number
motor to spin the disks and an actuator (motor) toposition * Surface number (when data is recorded on both sides of
the R/W head assembly across the spinning disks. the disk)
The storage capacity of a disk with multiple recording
The R/W head does not actually touch the platters, instead surfaces can be calculated as:
just barely skims above them, supported by a cushion of Storage capacity = No. of recording surfaces * No. of
moving air that is generated by the spinning of the platters. tracks per surface * No. of sectors
The rapid motion of the platters and heads inside the hard per track * No. of bytes per sector
46 Computer Fundamentals and Programming in C

Example 3.1 on the other hand


can transfer data at
Ahard disk has 10 disk plates, 2000 tracks per surface, 125 speeds ranging from
sectors per track, and 512 bytes of data can be stored per 400 to 800Mbps.
sector, Using this information, calculate the storage capacity The external hard
of the disk. drive can also be
connected to the
Solution computer wirelessly.
The disk has 10 plates, which means 20 recording surfaces. Figure 3.8 External hard disk External — drives
However, in a double-sided disk, the upper surface of the allow users to save
first disk and the lower surface of the last disk are normally sensitive, confidential, or otherwise important data on
not used for recording data because these surfaces may be them and kept at separate (away from the computer) secure
scratched easily, locations. As external hard drives are lightweight portable
Therefore, by using the formula, the storage capacity can devices, they can be easily carried away anywhere and also
be calculated as. be stored in a safe, secure location to protect the data from
theft or disaster. Moreover, some extemal devices come with
Storage capacity = 18 x 2000 x 125 x 512
security features like fingerprint recognition to prohibit other
= 2,30,40,00,000 bytes people from gaining access to the stored data
= 2x 10° bytes = approximately 2G8 External hard drives have high storage capacities.
External hard disks with a storage capacity of 2TB are
very common these days (1 TB = 1000GB), Therefore,
Advantages they are often used to back up numerous computer files or
serve as a network drive to store shared content.
Magnetic disks enable random access of data, which is
They are extensively used by people who do audio/video
useful for all types of real-world applications.
editing. These media files require high-quality settings, and
* They can be used as a shared device in a multi-user therefore consume a large amount of disk space,
ronment
are preferred for both online and offline storage of

* They can store large amounts of data. If required, the External hard disks are also called removable hard disks.
users can have multiple disks
* The cost of data storage is very low. With advancement
in technology, the cost of magnetic disks has reduced
and the capacity of data they can store has constantly OPTICAL DRIVES
increased.
Data transfer rate of magnetic disks is much higher than Optical storage refers to storing data on an optically
that of the magnetic tapes. readable medium by making marks in a pattern that can
be read using a beam of laser light precisely focused on a
Disadvantages spinning disk. Optical storage devices are the most widely
used and reliable storage devices, The most popular
* They must be stored in a dust-free environment optical storage devices are CD-ROM, DVD-ROM,
* They are larger in size and heavier in weight when CD-Recordable, CD-Rewritable, ete
compared to flash drives and optical disks. Today, every computer contains a CD-ROM drive.
A single CD can hold a large amount of data, including
software, movies, and songs. While some optical storage
EREB EXTERNAL HARD DISKS media is read-only, others are read- and write-enabled
An optical storage media consists of a flat, round,
As the name suggests, an external hard disk (sce Figure portable metal disk, which is usually 0.75 inches in
3.8) is a drive that is located outside the computer case diameter and less than sith of an inch thick. The disk is
in its own enclosure, It is used in addition to internal coated with a thin metal, plastic, or other material that is
hard drives to store data. It has become quite popular highly reflective.
because of its portability and high-storage capacity. It The optical disk stores information in the form of pits
is connected to the computer system with a high-speed and lands (shown in Figure 3.9). Pits are tiny reflective
interface cable, usually with plug-and-play interfaces bumps created with a laser beam and lands are flat areas
such as USB or FireWire, and may also contain a fan for separating the pits. While a land reflects the laser light and
cooling. While with USB connections, data can move at is read as binary digit |, a pit on the other hand absorbs the
arate of 12 to 480 Mbps (megabits per second), FireWire light and is read as binary digit 0.
Computer Memory and Processors 47

0000000000 10000000000 10000000000, rates (or speeds) ranging from 48X to 75X, or more. Here;
a 48X drive has a data transfer rate of 7200 kbps (i.c., 48 *
150 =7200) or 7.2 Mbps.

3.12.2 DVD-ROM
Digital video disk or digital versatile disk (DVD) is an
extremely high-capacity optical disk with storage capacity
ranging from 4.7GB to 17GB. DVDs are widely used to
store large databases, movies, music, complex software, ctc
Figure 3.9 Pits and lands Most of the DVD-ROMs are double-sided disks,
as they can store data on both the sides of the disk
Similar to magnetic disks, optical disks also have tracks Although 4 DVD-ROM resembles a CD-ROM in size
that are divided into sectors, but the shape of these sectors and shape, it stores information in different manner. A
is different from that of magnetic disks. Different types of DVD-ROM drive is compatible with CD-ROM drives
optical storage devices are explained in this section. and can therefore read CDs
A standard DVD can store seven times more data than
3.12.1 CD-ROM a CD because of its multi-layer storage technique and the
fact that the size of its pits and tracks is smaller. When
Compact disk read only memory (CD-ROM), shown data is recorded on a DVD, the laser starts on the inside of
in Figure 3.10, is a type of optical disk that uses laser the disk and moves outward, The laser beam has a smaller
technology to read and write data onto the disk. A single wavelength and can be focused on two different layers
CD-ROM can store a large amount of data, but once the on the disk. Data can be recorded on cach of the layers,
information is stored on it, it becomes permanent and thereby doubling the storage capacity of the disk.
cannot be altered. This means that the stored information In a double-sided DVD-ROM, two such disks are stuck
can only be read for processing, hence the name. back-to-back to allow recording on both sides, However,
such DVD-ROMs must be handled very carefully, as
both sides have data stored on them and this data can be
damaged accidentally due to mishandling

3.12.3 CD-R
Compact disk recordable (CD-R) is a blank disk that can be
used to store information. For example, users can use it to
store their databases, software, projects, assignments, etc
The process of writing data on the optical disk is called
Figure 3.10 CO-ROM burning. CD-R can be used in any CD-ROM drive and
Source: \talianphoto/Shutterstock/OUP Picture Bank is functionally equivalent to a pre-recorded CD-ROM.
However, once data is written on the CD-R, it cannot be
CDs are easily portable from one computer to another and changed. Moreover, the user can continue to store data
are therefore used to transfer data from one computer to on other parts of the disk until it is full. However, cach
another (similar to a floppy disk). The storage capacity part of a CD-R can be written only once and can be read
of a CD-ROM varies from 650 MB to 1GB, which is many times.
1000 times greater than that of afloppy disk. Nowadays, Today, many utility programs are available in the
most software products (such as Microsoft Office, market to write data on CD-Rs, but the most popular and
Windows operating system, and so on) are available on commonly used software for PCs is Nero Burning ROM.
CD-ROMs. CD-Rs are widely used to backup critical data, However,
to record information on a CD-R, the user must have a CD
CD-ROM drive The CD-ROM drive is used to read the writer. A CD writer or recorder (or simply CD-R drive)
information stored in a CD-ROM. The data transfer rate can also read information from a CD. The speed of these
of the first CD-ROM drive was 150 kbps (kilobytes per drives is up to 48X or more, and they are more expensive
second), and is denoted as X. The data transfer rate of a than ordinary CD-ROM drives.
CD-ROM is much slower than that of a typical hard disk
drive, which reads data at a rate of S—15 mbps (megabytes
per second), The speeds of all CD-ROM drives are
3.12.4 CD-RW
calculated relative to the first CD-ROM drive's speed. For Compact disk rewritable (CD-RW) is a new generation of
example, the CD-ROM drives used today have transfer erasable optical disks. The user can write and overwrite
48 Computer Fundamentals and Programming in C

data on the CD-RW disk multiple times. However, the


reliability of the disk tends to decrease, cach time you
Very soon a Blu-ray disk having 20 layers and storing 500
rewrite data. Both CD-Rs and CD-RWs can be used for
GB of data will beavailable in the market.
taking backup of important data. Moreover, CD-RWs are
also used to create audio CDs, so that users can record
their own music or movies on purchased CDs.
A CD-RW drive is used to write data on the CD-RW
USB FLASH DRIVES
Such drives have read and write speeds up to 48X or more, USB flash drives (Figure 3.11) are removable, rewritable,
but the re-write speed is 10X or more. The CD-RW drive
and are physically much smaller drives, weighing less
is advanced and more expensive than a CD-R drive. The
than 30g. In 2010, the storage capacity of the USB flash
CD-RW drive is compatible with both CD-R and CD-RW,
drives was as large as 256GB. Such devices are a good
and can therefore read or write data on both CD-R and substitute for floppy disks and CD-ROMs as they are
CD-RW disks,
smaller, faster, have thousands of times more ¢: and
are more durable and
3.12.5 BLU-RAY DISKS reliable. Until 2005,
Blu-ray disk (BD) is a new optical disk developed by most desktop and
the Blu-ray Dise Association (BDA), which includes laptop computers had
leading companies such as Apple, Dell, Hitachi, HP, floppy disk drives,
JVC, LG, Mitsubishi, Panasonic, Pioneer, Philips, but nowadays floppy
Samsung, Sharp, Sony, TDK, and Thomson. The disk drives have been
format of a Blu-ray disk was specifically developed Figure 3.11 USB flash drive abandoned in favour
to bring forward a recordable, rewritable disk that can Source: Coprid/Shutterstock/OUP of USB ports,
store large amount of data and display a high-definition Picture Bank A flash drive
video (HD), consists of a small
Although a Blu-ray disk has the same size as that ofa printed circuit board carrying the circuit elements and
CD ora DVD, it can store much more data than a DVD. a USB connector, insulated electrically and protected
A single-sided Blu-ray disk can store 25 GB of data and inside a plastic, metal, or rubberized case that can be
a dual-layer disk can store 50GB of data, While CDs carried in a pocket or on a key chain. The USB connector
and DVDs use a red laser to read and write data, the is often protected inside a removable cap, although it
Blu-ray disk on the other hand uses a blue-violet laser, is not likely to be damaged if unprotected, USB flash
hence the name Blu-ray. The advantage of using a blue drives draw power from the computer via external USB
laser with a shorter wavelength of 405 nm than the red connection
laser (650.nm) is that it allows it to focus the laser spot Uses of flash drives USB flash drives are useful in several
with even greater precision. This means that data can be ways.
packed more tightly and therefore stored in less space.
Moreover, the storage capacity of this disk is enough to Personal data transport Flash drives are used to transport
store a continuous backup copy of most people's hard and store personal files such as documents, pictures, and
drives on a single disk videos
A Blu-ray disk player is backwards compatible with System administration Flash drives are widely used by
CDs and DVDs and can therefore play a CD or a DVD system and network administrators to store configuration
despite the differences between the types of laser used. information and software used for system maintenance,
However, the Blu-ray disks will not play on CD and DVD troubleshooting, and recovery. They are also used to
players, because those players lack the blue-violet laser transfer recovery and antivirus software to infected PCs.
required to read the disks. As these drives have much larger storage capacities, they
Blu-ray disks will soon replace the use of CDs have also replaced CD-ROMs, which were earlier needed
and DVDs. They have already been supported by when reinstalling or updating a system.
about 200 of the world’s leading consumer electronics,
personal computer, recording media, video game, and Booting operating systems These days, PC firmware
music companies. Besides this, they are also being allows booting from USB drives. Such a configuration is
supported by Hollywood studios and a number of known as a live USB.
smaller studios that have already announced that they Music storage and marketing Digital audio files stored
will release new films on Blu-ray disks. Blu-ray disks on a USB flash drive can be easily transported from one
are also being used in physical distribution of video computer to another and played on a compatible media
games for PlayStation 3, Wii U, PlayStation 4, and player. Moreover, many home hi-fi and car stereo head
Xbox One. Sony’s Playstation 3 has a Blu-ray drive units are now equipped with a USB port, so that flash
installed in it drives can be connected to them.
Computer Memory and Processors 49

Brand and product promotion The casy availability of recommended when repairing a virus-contaminaléd
inexpensive flash drives has motivated companies to use host computer as there is a risk of infecting the USB
them for promotional and marketing purposes, particularly flash drive itself
within techni and computer-industry circles. USB * Flash drives are very small devices that can casily be
flash drives may be given away for free, sold at less than misplaced, left behind, or otherwise lost. This can at
wholesale price, or included as a bonus with another times be a serious problem, especially if the data is
purchased product. Usually, such drives are stamped with sensitive.
4 company’s logo, as a form of advertising. The drive may * The cost per unit of storage of a flash drive is higher
cither be empty or preloaded with graphics, documentation, than that of hard disks.
web links, Flash animation or other multimedia, and free
or demonstration software. ERTB memory carps
Backup Many users (especially involved in business)
use flash drives as a backup medium. However, one must A memory card (sometimes
remember that it is casy lose them and easy for people called aflash memory card ora
without a right to the data to make illicit copies. storage card, shown in Figure
Newer flash drives have much higher estimated 3.12) is a small device that can
lifetimes and are therefore available with warranties store digital files. They are
of five years, or more, Moreover, flash drives have easily portable from one place
experienced an exponential growth in their storage to another. A user can take a
capacity over time (following the Moore's law growth memory card, insert it into
curve). Today, flash drives of 256 GB are not uncommon. a computer, store files such
This has made them a very good substitute for magnetic Figure 3.12 Memory text documents, pictures,
disks, card audio files, and video file
and then remove the card and
Source: \tya Akinshin/
Advantages take it to another computer
Shutterstock/OUP Picture
Bank
where it can be again inserted
* Data stored on flash drives is impervious to damages
to copy the files onto the local
due to scratches and dust. disk of that computer,
* Flash drives are mechanically very robust and Technically, a memory card uses flash memory, which
computers these days come with a USB port, so they enables the users to add/delete files multiple times.
can be easily used to transfer data from one computer
Initially, when flash cards were first introduced in the
to another
market, they were not very large and were incredibly
* Flash drives have higher data capacity than any other
expensive. However, with advancements in technolog’
removable media.
memory cards have become cheaper and smaller in size.
* Compared to hard drives, flash drives use very little
Today, different types of memory cards are available in the
power and have no fragile moving parts
market. These include compact flash memory (which is the
* Flash drives are small and lightweight devices.
largest in size but has the smallest capacity to store data),
* Operating systems can read and write to flash drives
secure digmemory card (SD), miniSD card, microSD card,
without installing device drivers
memory stick, and the multimedia card (MMC). As these
* Specially manufactured flash drives have a tough
cards have evolved, they have become smaller in size and
rubber or metal casing designed to be waterproof and
larger in data capacity
virtually unbreakable. The data stored in these flash
Most of these cards have constantly powered non-
drives does not get destroyed even when submerged
volatile memory, which means that data is retained on thes
in water. Leaving such a drive out to dry completely
cards even when there is no power supply to the computer,
before allowing current to run through it has been and they do not need to be periodically refreshed. Memory
known to salvage the drive, with no further problems cards have no moving parts; therefore, they are unlikely to
in the future. suffer from mechanical difficulties.
Disadvantages Since newer memory cards are smaller, require |
power, have higher storage capacity, are completely
* Flash drives can sustain only a limited number of write silent, are less prone to mechanical failures, allow
and erase cycles before the drive fails. Therefore, flash immediate access to data, and are portable among
drives are usually not a good option to run application a greater number of devices, they are being widely
software or operating systems. used in the production of an increasing number of
* Most flash drives do not have a write-protect mechanism small, lightweight, and low-power devices, Although
to prevent the host computer from writing or modifying memory cards are far better than hard disks, they still
data on the drive. Wnite-protection devices are highly cannot replace them, because memory cards are quite
50 Computer Fundamentals and Programming in C

¢xpensive. For example, a compact flash card with one or more tape drives. As
192 MB capacity typically costs more than a hard drive shown in Figure 3.14, a tape 1
with a capacity of 40GB. library consists of a number of
slots to hold tape cartridges, a
ERER Mass STORAGE DEVICES barcode reader to identify tape
cartridges, and an automated
Mass storage refers to storing enormous amounts of data method called robot for
in a persistent manner, Mass storage devices can store up loading the appropriate tape
to several trillion bytes of data and hence are used to store on one of the tape drives for
large databases, such as the data of customers of a big retail processing. After processing,
chain and library transactions of students in a college. the robot automatically returns
Figure 3.14 Automated
Mass storage devices have the following advantages: the tape to the library.
Tape libraries can store
tape library
ainable transfer speed
* Low cost large amounts of data ranging from 20 terabytes to more
than 411 petabytes of data. They offer a cost-effective
* High data sto: wwe capacity
* Less weight
solution to the problem of storing large volumes of da
* Better tolerance of physical stress caused by shaking or
with the cost per gigabyte being at least 60 per cent less
dropping
than when using most hard drives. In addition, multiple
drives also lead to improved reliability because even when
+ Low power consumption
+ Easily portable one of the drives fail, the unit can still continue to function
with the other devices at a slower speed.
All these features make it convenient to use them with Though tape drives provide systematic access to
mobile phones, laptops, and desktops. Some of the very large quantities of data, the access is slow, varying
commonly used mass storage devices are discussed in this from several seconds to several minutes. A tape library
section. is commonly used for data backups as the final stage of
digital archiving. In organizations, it is extensively used
3.15.1 Disk Array for recording daily transactions or data auditing
A disk array, commonly known as a redundant array of
independent disks (RAID), is a group of one or more 3.15.3 CD-ROM Jukebox
physically independent and high-capacity hard disk
ACD-ROM jukebox, also known as an optical jukebox,
drives, which can be used in place of larger, single disk
an optical disk library, or a robotic drive, is a data storage
drive systems. The benefit of such a system is that it helps
reduce costs, because having several medium-sized hard device that can automatically load and unload optical
disks such as CDs and DVDs to provide terabytes and
disks is cheaper than having a single large hard disk
petabytes of tertiary storage (Figure 3.15). It can have
As shown in Figure 3,13, a disk array contains several
up to 2000 slots for disks and usually has a robot that
disk drive trays to improve speed and increase protection
traverses the slots and drives for loading the appropriate
against loss of data, The storage capacity of a disk armay is
several terabytes
(1 terabyte = | trillion bytes), The disk array
CD-ROM. After processing, the robot automatically
unit allows data to returns it back to the library
CD-ROM jukeboxes are extensively used for creating
be read or written to
any disk in the array.
backups and in disaster recovery situations, They can be
Disk armys are a
used for archiving data
(data is stored on media
vital component of
that will last up to 100
high-performance
years). Such archival
storage systems, and
their importance is
data is usually written
on disks of write once,
continuously growing
read many (WORM)
with the increase in
type so that it can never
demand to access
information for the be erased or changed.
Moreover, jukeboxes
day-to-day operation
are effectively used
Figure 3.13 Disk array of modem businesses.
for archiving data in
systems such as online
3.15.2 Automated Tape Library digital libraries, online
An automated tape library, also known as a fape silo, tape encyclopacdia, and
robot, or tape jukebox, is a storage device that contains online museums Figure 3.15 CD ROM jukebox
Computer Memory and Processors 51

DATA BACKUP

Data backup is the process of making one or more copies accidental deletion of a file, or a natural disaster like an
of data from an online storage device (hard disk) to a earthquake. In such cases, re-creating all the files would
tertiary storage device like a magnetic tape. The copy of take a lot of time, and at times, it might not even be
data acts as an offline storage so that if the system loses possible. Therefore, it is a good practice to take regular
the original data, it can be retrieved from the backup data backups so that the data can be retrieved within a
device and restored in the online storage device. short time. There are two types of data backups, which
The online storage system may lose its data because of can be compared as follows:
a disk crash, a virus attack, a hardware malfunction, an

Fall data backup Incremental data backup

* It copies allthe data on a teniary device, * Ncopies only newly created files or files
* The process takes from few minutes to hours changed since the last backup.
* Itis an expensive process interms of both * Bnceds fess backup time and storage space.
lime taken and storage space occupied. © Mis faster.
© Ibs slower. * is complex when compared to full
* It is simple. data backup

3.16.1 Execution Unit


Hierarchical storage management is a strategy that moves The execution unit mainly consists of the CU, ALU, and
less frequently used or unused documents from a fast registers,
magnetic disk to optical jukebox devices in a process called
migration. Ifthefiles areneeded, they are migrated back Control unit The main function of the CU is to direct
to the magnetic disk.
and coordinate the computer operations, It interprets the
instructions (program) and initiates action to execute
them. The CU controls the flow of data through the
ERTD Basic PROCESSOR ARCHITECTURE computer system and directs the ALU, r ters, buses,
and input/output (I/O) devices. It is, therefore, called the
As discussed in Chapter 1, a basic processor consists of brain of the computer system. Similar to the human brain,
two main parts— airthmetic and logical unit (ALU) and the CU controls all operations within the processor, which
in turn controls all other parts of the computer system, In
control unit (CU). Besides these components, there are
addition, the CU is responsible for fetching, decoding,
also registers, an execution unit, and a bus interface unit
executing instructions, and storing results.
(BIU) as shown in Figure 3.16.
Arithmetic and logic unit The ALU performs arithmetic
(add, subtract, multiply, divide, ete.), comparison (less
than, greater than, or equal to), and other operations.

Cache memory 3.16.2 Registers


A processor register is a computer memory that provides
Secondary Input quick access to the data currently being used for processing.
storage pe The ALU stores all temporary results and the final result in
devices Pen the processor registers. As mentioned earlier, registers are
at the top of memory hierarchy and are always preferred to
speed up program execution.
Registers are also used to store the instructions of the
Control Arithmetic program currently being executed. There are different
unit and types of registers, cach with a specific storage function.
logic unit
Accumulator and general-purpose registers These are
frequently used to store the data brought from the main
Figure 3.16 Basic computer organization memory and the intermediate results during program
52 Computer Fundamentals and Programming in C

€xccution. The number of general-purpose registers Decode Interpreting the instruction.


present varies from processor to processor. When
Execute Running the corresponding commands to process
program execution is complete, the result of processing is
the data.
transferred from the accumulator to the memory through
the memory buffer register (MBR), Store Writing the results of processing into memory,
Special-purpose registers These include the following This instruction cycle is repeated continuously until the
power is turned off
* The memory address register (MAR) stores the address
of the data or instruction to be fetched from the main 3.16.3 Bus Interface Unit
memory, The value stored in the MAR is copied from
the program counter, The BIU provides functions for transferring data between
* The MBR stores the data or instruction fetched from the execution unit of the CPU and other components of
the main memory (Figure 3.17), If an instruction is the computer system that lie outside the CPU, Every
fetched from the memory, then the contents of the computer system has three different types of busses to
MBR are copied into the instruction register (IR). If a carry information from one part to the other. These are the
data is fetched from the memory, the contents are either data bus, control bus, and address bus (Figure 3.19).
transferred to the accumulator or to the VO register. The Address bus
MBR is also used while writing contents in the main
memory. In this case, the processor first transfers the r
contents to the MBR, which then writes them into the RAM [nom|Primer|Disk Moni Keyhoud
memory, cru
Reads Data bus
Processor | [Memory butterregister | | Memory| he Control bus
Figure 3.17 Data to and from memory comes from and to
processor through the MBR Figure 3.19 Buses with a computer system
The BIU puts the contents of the program counter on the
* The IR stores the instructions currently being executed. address bus. Note that the content of the program counter
In general, an instruction consists of two parts is the address of the next instruction to be executed, Once
operation and address of the data on which the operation the memory receives an address from the BIU, it places
has to be performed. When the IR is loaded with an the contents at that address on the data bus, which is then
instruction, the address of the data is transferred to the transferred to the IR of the processor through the MBR, At
MAR and the operation part is given to the CU, which this time, the contents of the program counter are modified
interprets it and executes it (c.g., incremented by 1) so that it now stores the address of
* The I/O register is used to transfer data or instructions to the next instruction.
or from an I/O device. An input device transfers data to
the /O register for processing. Correspondingly, any data 3.16.4 Instruction Set
to be sent to the output device is written in this register.
* The program counter The instruction set is a set of commands that instructs the
stores the address of processor to perform specific tasks. It tells the processor
Store Fetch the next instruction to what it needs to do, from where to find data (register,
be executed. memory, or I/O device), from where to find instruction,
and so on. Nowadays, computers come with a large set
The size of a register is of instructions, and each processor supports its own
usually specified by the instruction set. Although the instructions across processors
number of bits it can store.
are almost the same, they may vary in their internal design.
For example, a register can
A basic set of instructions that is supported by every
be of 8 bits, 16 bits, 32
Execute Decode processor is given in Table 3.12
bits, or 64 bits. Higher the
An instruction set can be built into the hardware of the
register size, more the data
processor or it can be emulated in the software, using an
Figure 3.18 Instruction cycle that can be stored in it
Instruction cycle To execute an instruction, a processor
normally follows a sect of basic operations that are Every instruction contains two parts—opcode and
together known as an instruction cycle (Figure 3.18). The operand. Opcode specifies the instruction to be
operations performed in an instruction cycle involve the performed (e.g., ADD, SUB) and operand isthe data (e.g.,
following in register, in memory, oravailable through |/O device)
Fetch Retricving an instruction or a data from memory on which the instruction is tobe applied.
Computer Memory and Processors 53

interpreter. The hardware design is more efficient and fast?


LELCEe® Basic instruction set
for running programs than the emulated software version,
Instruction |Purpose Example |Comment
ADD Toaddtwo = =ADD AX and BX are 3.16.5 System Clock
sumbers AX, BX processor registers A small quartz crystal circuit called the system clock
that hold data. controls the timing of all operations within the computer
SUB To subtract SUB AX and BX are system. The system clock regularly generates ticks to
control the functioning of the computer. Every processor has
two numbers AX,BX processor registers
that hold data. a system clock to synchronize various operations that take
place within the computer system. Many modern computers
MUL To multiply MUL AX and BX are even have multiple system clocks that vibrate at a specific
two numbers AX, BX processor registers frequency. When we talk of the system clock, two important
that hold data. questions need to be answered. First, how does the system
clock affect the speed of the processor? Second, why is there
DIV To dividetwo DIV AX and BX are a need for multiple clocks within a single computer system?
numbers AX, BX processor registers Clock speed is measured by the number of ticks
that hold data. per second, where a tick is the smallest unit of time in
CMP To compare CMP AX stands for the which processing is done. A processor can perform some
two numbers AX,BX accumulator.
operations in a single clock tick, whereas others may
require more ticks. The ticking of the clock drives the
IN To inputdata INPDX DX is a processor circuits in the computer. Therefore, faster the clock ticks,
from a device register. more is the number of operations that can be performed
(considering other factors to be the same).
OUT To output ouT Data to be output Nowadays, processors have system clocks with speeds
data toa DX is in DX. in the gigahertz range, where giga stands for billion and
device hertz means one cycle per second. Therefore, a computer
that operates at 3GHz has three billion clock cycles in
JMP To jump JMP MAIN is the name
one second, which means that the computer can perform
to another MAIN of the location.
more than one billion operations in a second, Hence, clock
address in
memory
JMPIF To jump JIMPZ The program will Other factors that can affect a computer's performance
fo another MAIN goto MAIN if the include the type of processor, availability of cache
address in (Gump if value is equal to memory, memory access time, and speed of BIU.
memory zero) zero.
only when speed is one of the factors that have a profound effect on a
the specified computer's performance
condition is Initially, computers had a single unified system clock that
true operated at a very low speed. This clock was connected
with the processor, memory, and other components. As
LOAD LOAD The data will the technology advanced, some devices could operate at
AX be loaded from a much higher speed than others. However, a single slow
memory in the speed clock could not drive the components that operated
accumulator. at different speeds, Hence, computers today have four or
five different clocks, each operating at a different speed.
STORE STORE The data in
AX accumulator
will be stored in 3.16.6 Processor Speed
memory. The speed of PCs and minicomputers is usually specified in
CALL CALL — Call a subroutine
MHz or GHz. However, the speed of a mainframe computer
is measured in MIPS (millions of instructions per second)
PROC named Proc.
or BIPS (billions of instructions per second) and that of
RET RET - @ supercomputer is measured in MFLOPS (millions of
floating-point operations per second), GFLOPS (giga or
billions of floating-point operations per second), or TFLOPS
(10° floating-point operations per second). The reason for
54 Computer Fundamentals and Programming in C

the variations in speed is that personal or minicomputers architecture is like having two separate processors installed
use a single processor to cxecute instructions, whereas in the same computer. However, since the two processors
mainframes and supercomputers employ multiple processors are actually plugged into the same socket, the connection
to speed up their overall performance. between them is faster. Ideally, such processors must be
twice as powerful as a single-core processor, but in practice,
3.16.7 Pipelining and Parallel Processing their performance is only about one-and-a-half times more.
Computers working on high-end applications, such as
Most of the modern PCs support pipelining, which is a artificial intelligence and weather forecasting, go a step
technique with which the processor can fetch the second further by implementing the concept of massively parallel
instruction before completing the execution of the first processing, that is, large-scale parallel pro ing. Ino
instruction. Initially, a processor had to wait for an multi-core processor, tens or hundreds of processors are
instruction to complete all stages before it could fetch the incorporated in @ single chip. Companies such as IBM,
next instruction, thereby wasting its time. However, with AMD, and Intel have already come out with multi-core
pipelining, processors can operate at a faster pace as they no chips for desktops, laptops, and servers, These multi-core
longer have to wait for one instruction to complete before chips are available as dual core (2 processors per chip),
fetching the next instruction. Such processors that can quad core (4 processors per chip), 8 core, and 16 core.
execute more than one instruction per clock cycle are called
superscalar processors. Instruction execution without
pipelining and with pipelining are shown in Figure 3.20.
Since multi-core processors generate less heat and
With superscalar architecture, processors could
consume less power, they are also called energy-efficient
execute programs faster by replicating components
like ALUs. Replication was the only possible solution ‘OF power-aware processors.
because a single processor was already made to work at
3.16.8 Types of Processors
its maximum limit
The other technique to enhance a computer's A computer is a combination of hardware and software.
performance is to have parallel processing. With this However, companics often argue about the role that
method, multiple processors can be used simultancously hardware and software should play in the design of
to execute a single program or task, In parallel processing, processor architecture, Companies like Intel want the
a complex and large task is divided into smaller tasks in hardware to bear more responsibility than the software
such a way that cach task can be allocated to a processor. so that the software can be simple and casy; companics
Thus, multiple processors work together simultaneously like Apple, on the other hand, want the software to lead.
on the sub-parts of the task assigned to them, Based on these entirely contrasting opinions, there are two
Parallel processing systems need 4 special software to major processor architectures—complex instruction set
determine how the problem will be divided and then, at computer (CISC) and reduced instruction set computer
a later stage, how the sub-solutions will be combined to (RISC)
form the final solution of the problem.
Modern-day PCs implement parallel processing by using Complex Instruction Set Computer
dual-core processors or multi-core processors. Dual-core
Intel's hardware-oriented approach has given rise to CISC
architecture in which more complexities have been added
in the hardware to allow the software to be simpler, In
CISC machines, most of the instructions are implemented
using hardware. The hardware in such machines is capable
of understanding and executing the instructions. For
example, in a CISC machine, when multiplication needs
to be performed, the programmer just has to write the
Instruction | name of the instruction and its operands (¢.g., MUL 2, 3).
The processor will automatically load the data values in
Instruction 2 processor registers, multiply them in the execution unit,
and store the result. The advantages of CISC processors
Instruction 3 include the following
* Programs can be very simple and short,
Instruction 4 * Short programs require less memory space.
* Less effort is required by the translator (discussed
in Chapter 6) to convert the program into machine
(b) Machine cycle (with pipeline) language
Figure 3.20 Instruction execution with and without pipelining * Faster execution of instructions is possible.
Computer Memory and Processors 55

However, on the downside, CISC machines require companies to decide on the efficient use of space on W
additional hardware circuitry to handle instructions. microprocessor.
This adds to the complexity and cost of the processor's Although RISC machines are less complex and less
hardware circuitry. Therefore, CISC processors are more expensive, they place extra demand on programmers to
expensive than RISC processors. implement complex computations by combining simple
instructions. Unlike CISC machines, programs developed
for RISC machines have more lines of code. Therefore,
they require more memory space and more effort from a
Majorityof the PCs use CISC processors.
translator to convert the code into machine language.

Reduced Instruction Set Computer


Whether RISC or CISC is used depends on the application.
Apple's software-oriented approach has led to RISC For some applications, RISC performs better, whereas for
architecture, which utilizes a small but highly optimized others, CISC will bepreferable.
set of instructions, A research done by IBM found that
20 per cent of the instructions perform 80 per cent of Since both RISC and CISC have their own advantages, the
the work in computers. Programmers rarely used many recent trend is the convergence of these two technologies.
instructions, and so companies wanted to reduce the The lines between the two architectures have begun to blur
number of instructions and to have only frequently as both the architectures have started adopting cach other's
used instructions in the hardware. Others could be strategy. For example, pipelining, which is an important
implemented in the software using the basic instructions concept of RISC machines, is now being implemented in
set, The main principle of RISC is that it takes long and CISC machines. Similarly, RISC machines are adopting
complex instructions from a CISC design and reduces it superscalar execution and are also moving towards having
to multiple shorter instructions, which can execute faster more transistors on a single chip to incorporate more
The simplicity of RISC gave more freedom to computer complicated, CISC-like commands,
oo,
POINTS TO REMEMBER
Computer memory is an internal storage area in the Most computers contain a small amount of ROM that
computer that is used to store data and programs stores critical programs like the BIOS which is used to
either temporarily or permanently. boot up the computer when it is turned on. The BIOS
While the main memory holds instructions and data consists of a few kilobytes of code that tells the
when a program is being executed, the auxiliary or the computer what to do when it starts up, e.g., running
secondary memory holds data and programs not hardware diagnostics and loading the operating
currently in use and provides long-term storage. system into the RAM,
To execute a program, all the instructions or data that © Magnetic tapes are mass storage devices capable of
has to be used by the CPU has to be loaded into the backing up and retaining large volumes of data, They
main memory. However, the primary memory is are available in the form of cassettes, reels, and
volatile, so the data can be retained in it only when cartridges.
the power is on, Moreover, it is very expensive and Floppy disks are data storage devices that consist of a
therefore limited in capacity, thin magnetic storage medium encased in a square
On the contrary, the secondary memory stores data or plastic shell.
instructions permanently, even when the power is Hard disk drive is a storage device, which is a part of
turned off. It is cheap and can store large volumes of the general-purpose computers and is used for storing
data. Moreover, data stored in auxiliary memory is data on a set of disks that are stacked together like
highly portable. phonograph records.
Processor registers are located inside the processor The optical disk stores information in the form of pits
and are therefore directly accessed by the CPU. Each and lands. Pits are the tiny reflective bumps created
register stores a word of data (which is either 32 or 64 with a laser beam, and lands are flat areas separating
bits). Registers are the fastest of all forms of computer the pits. While a land reflects the laser light and is
data storage. read as binary digit 1, a pit on the other hand absorbs
Cache memory is an intermediate form of storage the light and is read as binary digit 0.
between the ultra-fast registers and the RAM. Cache The CU directs and coordinates the computer operations.
memory is basically a portion of memory made of The BIU provides functions for transferring data
high-speed SRAM instead of the slower and cheaper between the execution unit and other components of
DRAM, which is used for main memory. the computer system that lie outside the CPU,
56 Computer Fundamentals and Programming in C

* Pipelining is a technique with which the processor can * In parallel processing, multiple processors can be used
fetch the second instruction before completing the simultaneously to execute a single program.
execution of the first instruction.

>
GLOSSARY
Basic input output system (BIOS) Program that tells Offline storage Data storage device on which the data Is
the computer what to do when it starts up, e.g., running recorded and then physically removed or disconnected
hardware diagnostics and loading the operating system (off the computer). For example, magnetic tapes, floppy
into RAM. disks, optical disks, flash memory, and external hard disks.
Cache memory An intermediate form of storage between Optical storage Storing data on an optically readable
the ultra-fast registers and the RAM. medium by making marks in a pattern that can be read
Computer memory An internal storage area in the using a beam of laser light precisely focused on a spinning
computer used to store data and programs either disk. The most popular optical storage devices are
temporarily or permanently. CD-ROM, DVD-ROM, CD-R, and CD-RW.
Data transfer rate The time taken to transfer data or the Primary memory It is also known as main memory or
time taken to read/write to a disk. internal memory; the only type of memory that Is directly
Disk latency The sum of the seek time and the rotational accessed by the CPU, which continuously reads and
delay. It is actually the time taken to initiate a transfer.
executes instructions stored in the primary memory.
DRAM A type of RAM that must be refreshed multiple Programmable read-only memory A type of ROM that
times in a second to retain its data contents. can be programmed using high voltages,

Erasable programmable read only memory A type of Rotational delay The time taken to bring the target sector
ROM that can be erased and re-programmed. The EPROM to rotate under the R/W head
can be erased by exposing the chip to strong ultraviolet Seek time The time taken to position the R/W head over
light. the appropriate cylinder.
Flash memory A type of EEPROM in which the contents SRAM A type of RAM that holds data without an external
can be erased under software control. The most flexible refresh as long as it is powered. It is made of D flip-flops in
type of ROM. which the memory cells flip-flop between 0 and 1 without
Hard disk A set of disks stacked together like phonograph the use of capacitors.
records, which have data recorded electromagnetically in Superscalar processors Processors that can execute more
concentric circles known as tracks, than one instruction per clock cycle.
Instruction set A set of commands that instructs the System clock A small quartz crystal circuit that controls
processor to perform specific tasks. the timing of all operations within the computer system.

EXERCISES
Fill in the Blanks is a one-time programmable ROM
1, The memory holds data and programs that are 8. The flash memory is also a type of
currently being executed by the CPU. 9. Digital cameras and mobile phones have
2. memory is volatile. memory.

3, memory stores data or instructions 10, The number of cylinders of a disk drive is equal to the
permanently. number of
4. are the fastest of all forms of computer data 11. The process of writing data to a optical disk is called
storage.
5. Aprocessor register can store _ bytes. 12. The most popularly used software for writing data on
6, Static RAM is made of CDRsis_
‘Computer Memory and Processors 57

13. Data on a magnetic tape is represented using the (a) MAR (b) program counter
code (c) MBR (d) IR
| are concentric circles and _ are pie- 8. The speed of supercomputers is specified by
shaped wedges on a track.
{a) GHz (b) GIPS
15. The time taken to R/W data to a disk is called
(c) GFLOPS (d) all of these
16.____ unit directs and coordinates the computer
operations.
State True or False
17. Intermediate results during program execution are
1. Primary memory is faster than secondary memory.
stored in
2. Cache memory is made of ORAM
18. stores the address of the data or instruction to
3, L2 caches are built into the motherboard outside the CPU.
be fetched from memory.
4. An SRAM chip can hold more data than a DRAM chip of
19. Aninstruction consistsof and
the same size.
20. The instruction cycle is repeated continuously until
5. EPROM can be erased by exposing the chip to strong
ultraviolet light.
21. Buses in a computer system can carry
a 6. PROM allows its entire or selected contents to be
electrically erased
22. Inan instruction, specifies the computation to
7. Seek time is the time taken to bring the target sector to
be performed.
23. A: is the smallest unit of time in which
rotate under the R/W head.
processing is done.
8. CD-Rs can be written only once and can be read as many
times.
24. The speed of PCs and minicomputers is specified in
OF 9. Operating systems can read and write to flash drives
without installing device drivers
25. Gigais and tera is =
10. Memory cards use flash memory to store data.
26. processors are power-efficient processors
11. The ALU initiates action to execute the instructions,
12. The value stored in the program counter is copied from
Multiple-choice Questions
the MAR
1. The memory used by the CPU to store instructions and
data that are repeatedly required to execute programs 13. The program counter stores the address of the next
to improve overall system performance is instruction to be executed
14. The executing unit provides functions for data transfer.
(a) primary memory (b) auxiliary memory
15. A processor can perform all operations in a single clock
(c) cache memory (d) flash memory tick,
2. Magnetic tapes, floppy disks, optical disks, flash memory,
16. Computers can have at most one clock.
and hard disks are examples of
17. The speed of a mainframe computer is measured in MHz
(a) primary memory (b) auxiliary memory or GHz.
(c) cache memory (d) flash memory 18. Personal computers support pipelining.
3. The time taken to initiate a transfer is called 19. Pipelining needs replication of components
(a) seek time (b) rotational delay 20. Parallel processing can be implemented only on server
(c) data transfer rate (d) disk latency machines.
4. Disk address is specified using 21. In RISC machines, most of the instructions are
(a) sector number (b) track number implemented using hardware.
22. An instruction set can be implemented only using an
(c) surface number (d) all of these
opcode.
5. The memory used in MP3 players, PDAs, laptops, and
digital audio players is Review Questions
(a) primary memory (b) optical memory 1. What do you understand by computer memory?
(c) cache memory (d) flash memory 2. Differentiate between primary memory and secondary
6. The component of the processor that controls the flow memory.
of data through the computer system is 3. Give the characteristics of the memory hierarchy chart.
(a) BIU (b) execution unit 4. What is a BIOS? Which kind of memory is preferred in it,
(c) CU (d) ALU and why?
7. While transferring data from memory into the processor, 5. Differentiate between static RAM and dynamic RAM
the register that is used as an intermediate placeholder 6. Give the organization of computer memory. How does
of the data is the CPU access a memory cell?
58 ‘Computer Fundamentals and Programming in C

7. Explain the working of a magnetic disk. What do you understand by re-programmable ROM
8. How is data stored on optical storage devices? chips?
9. A DVD-ROM can store more data than a CD-ROM of the Discuss the different types of optical storage devices.
same size. Comment. Draw and explain the basic architecture of a processor.
10. What is a USB flash drive? ‘Control unit is the brain of the computer.’ Justify.
11. Write a short note on memory cards What are special-purpose registers?
12. Give the formulas used to calculate the storage capacity Define instruction cycle.
of magnetic disks, floppy disks, and magnetic tapes. Differentiate between pipelining and parallel processing.
Which of these have the highest storage capacity? How can pipelining improve processor performance?
Explain with the help of relevant examples. What are multi-core processors?
13, What is a head crash? How does it occur? Differentiate between RISC and CISC.
14. Briefly discuss the importance of cache memory.
>: _ _ Number Systems and
‘Computer Codes
TAKEAWAYS
* Number systems * BCD © Weighted codes
* Binary number system * ASC © Gray code
* Octal number system * EBCDIC * Unicode
* Hexadecimal number system * Excess code

CEB INTRODUCTION TO NUMBER SYSTEMS At position 0,


At position 1, d
At position 2, d;
Data is stored in a computer in the form of 0s and Is. This
is because computers understand only binary language
(which consists of just two digits, 0 and 1). Therefore, for a
computer, all data and information is reduced to numbers. We can form the number using the aforementioned
Whether the user stores songs, pictures, numbers, or information as follows:
documents, all information is treated as binary numbers. (NYT = dyn 8+. + dor + dl + + dg ™
In this chapter, we will learn about the different types
of number systems used in computers as well as different =100* 2410x341" 4+0.1x5+0.01x6
types of codes that convert human language, consisting = 200 +30+4+0.5+0.06
of numeric and alphanumeric characters, into machine = 234.56
language (in binary code) which the computer understands.

Representation of Numbers in Radix r


Before considering number systems, let us first understand
the haseorradix of a numbersystem, The number of unique
CRD inary numBer sysTEM
digits used to form numbers within a number system is
called radix of that system. For example, in the decimal Computers are electronic machines that operate using
number system we use digits 0-9 to form numbers; thus, binary logic. These devices use two different values to
its radix is 10. represent the two voltage levels (0 V for logic 0 and +5 V
A general number system (Njr of radix r can be for logic 1), Therefore, the two values,0and |, correspond
represented as follows: to the two digits used by the binary number system,
(Nyr = d,y 7! + + dyt+ dy! + The binary number system works like the decimal
number system, with the following exceptions:
where r= radix
d, = Digit at position i-m<sisn-1 * While the decimal number system uses base 10, the
= Weight of position /-m <isn—-1 binary number system uses base 2
a = Number of integral digits in NV * The decimal number system uses the digits 0 to 9, but
m= Number of fractional digits in N the binary number system uses only two digits, 0 and |
Digits in radix r number system include 0, .... r—1
Some important terms in the binary number system include
Example 4.1 the following
+ Bit is the short form of ‘binary digit’. It is the smallest
Let us consider a decimal number 234.56, Form the number possible unit of data. In computerized data, a bit can be
using the aforegiven radix representation either 0 or I
60 Computer Fundamentals and Programming in C

* Nibble is a group of four bits.


Binary representation with four bits
* Byte is a group of eight bits. A nibble is a half byte. Bits
0-3 are called the low-order nibble, and bits 4-7 form Number of bits: 4
the high-order nibble Data values that can be represented = 2‘ = 16 |
Word is a group of two bytes. Bits 0-7 form the low-
Decimal value | Binary value |Decimal value | Binary value
order byte and bits 8-15 form the high-order byte.
0 0000 8 1000
However, computers today have redefined word as a
group of four bytes (32 bits). ! 0001 9 1001
2 0010 10 1010
Table 4.1 lists these terms in the binary number system
with examples. 3 ool i tou
4 0100 be] 1100,
5 101 3 Hob
LC® Some important terms in the binary number
6 ono 4 to
system
7 On 1s Witt
Term | Size (bits) Example
|Bit 1 0
|Nibble 4 1010 Applications of Binary Numbers
|Byte 8 0101 1100 * The binary system is best suited to be used with computers,
(Word 16 6101 11000101 1100 as mechanical and electronic relays recognize only two
states of operation—on/off or closed/open. In the binary
number system, character | on © closed circuit © true
Now let us understand how much data can be encoded and character 0 =off «open circuit false.
in the binary form using different numbers of bits. If we Binary numbers can be casily translated into electrical
have a single bit, we can represent only 2! 2 values, 0 or impulses.
1. With two bits, we can represent 2° = 4 values, namely * The binary system can be effectively used to encrypt
00, 01, 10, and 11, Tables 4.2-4.4 illustrate this concept messages
better + The binary system is the backbone of the development
of computer science and many forms of electronics. It
led to the development of devices such as typewriter,
Table 4. Binary representation with two bits
cathode ray tube, telegraph, and transistor
Number of bits: 2 * Binary number system is also used in statistical
Data values that can be represented = 2° = 4 investigations
and probability studies to explain strategy,
Decimal Binary value
prove mathematical theorems, and solve puzzles
value
| 0 00 CED WORKING WITH BINARY NUMBERS
| 1 oO
| 2 10 We all are very familiar with how decimal numbers operate
, 3 u The same concept can be applied to binary numbers (base
2), octal numbers (base 8), and hexadecimal numbers
(base 16). So before discussing other number systems,
ACC Binary representation with three bits let us first take a look at how we form a number in the
decimal number system.
Number of bits: 3 Suppose we have a decimal number 123, what do you
Data values that can be represented = 2' = 8 call this number? How did you get its value? The answer
Decimal Binary Decimal Binary is that we first arrange individual digits into columns and
value value value value then multiply each digit with the value of its position
Figure 4,1 illustrates this concept
0 000 4 100

1 oo1 $ 101 Hundreds(10°)Tens (10) | Ones (10?)

2 O10 6 110 Decimal 1 | 2 3

| 3 ol 7 Lb Figure 4.1 Position of the digits of 123 using the decimal


number system
Number Systems and Computer Codes fo

Here, 123=1* 100+2*10+3*1 Step3: Repeat Step 2 until all the bits have been
or 123=1 10? +2 10'+3 = 10° Step4: Add the end result of each worked power of 2 to
The same concept is applicable to the binary number get the decimal number.
system, the only difference being that wherever 10 is used,
it is replaced by 2 as shown in Table 4.5.
4.3.2 Converting aDecimal Number into
4.3.1 Converting a Binary Number into
Binary Form
Decimal Form
To convert a decimal number into its binary equivalent,
In a binary number, all the columns are powers of 2. simply divide the decimal number by 2 and then write
Table 4.5 shows the five least significant digit place holders. down the remainder, repeat this process until the number
cannot be divided by 2 anymore,
Five leastsignificant
digitplaceholders
Example 4.4
(‘Sixteen's Eight’s Four's Twos One's i"
column | column | column | column | column (LSB) | Convert decimal 13 of (13),q into its binary equivalent.

2 oe || 2 Solution
2,13 |R
21641
Note that, in Table 4.5, all the columns are specified in 2 | 3 | 0 Now write the result starting from the
powers of 2. Hence, in order to convert a binary number
into its decimal equivalent, multiply that place holder value 2 | 1 [| 1 last remainder obtained, Therefore, (13),o =
(power of 2) with the bit, and then add all the products. 10} 1 (1102),
—___——
Example 4.2
Example 4.5
Convert 1101 into a decimal number.
Solution Convert 169 into its binary equivalent.
Use Table 4.5 to form the decimal number. Solution
Decimal number = 1x 27412? +0x2!+1x%2° 21 169|R
=1x8+1x44O0x2+1x1
2) 8i1
=8+4+0+1
=13 2) 4210
2) 210
24 30/1
21 510
i
2] 211 Nowwrite
the result starting from the last
Convert 1010 1001 into adecimal number.
21110 remainder obtained.
Solution
Decimal number = 1 x 2’ +0 x 2°+ 1% 2° +0 2*+1x2° | 0 | 1 Therefore, (169),,
=(1010 1001),.
+0x2?4+0x 2'+1%2°
=1x 128 +0x64+1x32+0x16+1x8+
Ox4+O0x241x1
4.3.3 Adding Two Binary Numbers
=128+0+32+0+8+0+0+1
=169 Adding binary numbers is similar to the addition of
The following steps summarize the procedure to convert a decimal numbers. While performing binary addition,
binary number into a decimal number. start by adding the bits (digits) in one column at a time,
from right to left as we do in the case of adding decimal
Step 1: Start with the least significant bit (LSB) and multiply numbers. However, to perform binary addition, one must
that bit with 2°. Note that any number raised to O is remember the rules of addition.
always 1,
Step 2: Continue working from right to left. Multiply each Rules of Binary Addition
bit with an incremental power of 2 (i.e., 2°, 27, 2°, + 0+0=0 *0+1=1 -1+0=1
2", ete). + 1+1=0, and carry | to the next more significant bit.
62 Computer Fundamentals and Programming in C

Consider the following examples: be used to restructure the subtraction problem into an
addition problem. This is called subtraction by the two's
0001010 1010101
+ 0100100 + 0101010
complement method.
0101110 Liditit Step 1: To subtract two binary numbers using two's
complement, first find the two’s complement of the
number to be subtracted (subtrahend). Two's complement
i Carry iii Carry is calculated in the following two steps:
1011 1010101
+ 0001 + 0101110
+ Complement cach bit of the number, That is, change |
to 0 and 0 to I. The resultant number is said to be in
1100 _10000011
one x complement form.
+ Add 1 to the resultant number in one’s complement
4.3.4 Subtracting Two Binary Numbers form to get the corresponding two ¥complement
Now that you have learnt to perform addition on two Step 2: Add the minuend and subtrahend (which is now in
binary numbers, subtraction will also be an casy task to two's complement form). Take care of the carries in each
perform. As with binary addition, there are certain rules column, and discard any carry bit that extends beyond
to be followed for binary subtraction. These rules can be the number of bits of the original number or the two's
summarized as: complement
* 0-0-0 *1-0=1 *1-1=0
However, an important point to note here is that when
+ 0—1=0, and borrow | from the next more significant bit subtracting binary values it is important to maintain the
same number of bits for cach number (minuend and
subtrahend). For this, you may pad the number with extra
Note that the value borrowed from the next more zeroes to the left of the value
significant bit depends on the base of the number system You should also remember to discard the carry obtained
and is always the decimal equivalent of the base. Hence, after adding the last bits. Observe the following examples,
in the decimal number system, 10 is borrowed, in binary which will help make the concept clear.
2 isborrowed, in octal 8 isborrowed, and in hexadecimal
16 is borrowed, Example 4.6
Consider the following examples Calculate 1011 — 1001 using two's complement method.
00 Solution
1011 10110111 +001 10
Step 1: Find the two's complement of the subtrahend.
- 1001 00110010 0101010
Subtrahend = 1001
0010 10000101 0101100
One’s complement of subtrahend = 0110
MW Two's complement of subtrahend = 0110 + 1 =0111
00 22 22 Step 2: Add the minuend and the two's complement of
104401 $000101 104401 the subtrahend.
—0011000 1011
~ 0101101 +0111 Now discard the carry from the last bit;
1.0010 hence the result = 0010.
2122
062002
libretto Minuend
1o1olid Subtrahend Example 4.7
OOM Difference
Calculate 10110111 — 00110010 using two's complement
4.3.5 Subtracting Two Binary Numbers Using method.
Two's Complement Solution
Though the previously discussed technique of subtracting Step 1: Find the two's complement of the subtrahend
two binary numbers is simple, there is another way to Subtrahend = 00110010
perform subtraction. In this technique, subtraction is One’s complement of subtrahend = 11001101
done through addition, Do you recall having learnt in Two's complement of subtrahend = 11001101 +1
school that a positive number subtracted from another = 11001110
positive number is the same as a negative number added Step 2: Add the minuend and the two's complement of the
to a positive number? This fundamental concept can subtrahend.
Number Systems and Computer Codes (os

10110111 4.3.7 Dividing Two Binary Numbers


+ 11001110
Binary division is again similar to dividing two decimal
1 10000101
numbers. According to the long division method, the
Now discard the carry from the last bit; hence the divisor is multiplied with the quotient, and the result is then
result = 10000101. subtracted from the dividend.
Consider the following examples to understand the
concept better.
Example 4.8
0011 O10 OO101111
Calculate 1010110 — 0101010 using two's complement 11) 1001 ( 10) 111011 ( 101 ) 11101110¢
method. 1] 0 i]
Solution 10 1 11
Step 1; Find the two’s complement of the subtrahend.
o 10 a
100 i Mt
Subtrahend = 0101010
One’s complement of subtrahend = 1010101
4 10 101
i 10 100
Two's complement of subtrahend = 1010101 + 1
i 10 0
= 1010110
o ol 1001
Step 2: Add the minuend and the two’s complement of the
0 LOL
subtrahend,
i 1001
1010110
+.1010110 Nowdiscard the carry from the last
10 LOL
ak 1001
10101100 bit; hence the result «0101100
LOL
1000
LOL
4.3.6 Multiplying Two Binary Numbers AL
Binary numbers are multiplied in the same manner as we
multiply two decimal numbers.
Two numbers A and 8 are multiplied using partial
OCTAL NUMBER SYSTEM
products. For each bit in 8, the product of that bit with The octal number system is the base 8 number system
the corresponding bit in A is calculated and written on a which uses digits 0-7, This number system was used
new line (shifted leftward). The partial products are added extensively in carly mainframe computer systems, but
together to get the final result. has become less popular in comparison with binary and
The rules of multiplication of binary numbers are the
hexadecimal number systems,
same as that of decimal numbers, that is:
Octal decimals operate in the same manner in which
+ Ox 080 *Ox1l=0 decimal and binary numbers operate. In the octal
° 1x0=0 eixtlel number system, each column is a power of 8 as shown
Consider the following examples to understand this concept. in Table 4.6.

1010 * 11 = 11110 1011 * 1001 = 1100011


Decimal, binary, and octal number systems
1010 1011
x11 x1001 Fourth Third
1010 1011
digit
digit
mas

10100 00000
11110 000000
1011000
1100011
111010= 101 = 100100010
4.4.1 Converting an Octal Number into
111010
Decimal Form
«101
111010 Try to recall what we did to convert a binary number into
0000000 its decimal equivalent; the same steps can be applied to
11101000 convert an octal number into decimal. The only difference
100100010 is that we will use base 8 insteadof base 2.
64 Computer Fundamentals and Programming in C

Tn order to convert an octal number into its decimal 8 | 12 | 2 Nowwrite the result starting from the last
equivalent, multiply that place holder value (power of 8) 8 | 1 |4 remainder obtained. Therefore, (786),, =
with the digit, and then add all the products
| 0 | 1 (1422),

Example 4.9 ——
Convert (123), into its decimal equivalent
Example 4.12
Solution
Use Table 4.6 to form the decimal number. Convert (9890), into its octal equivalent
Decimal number = 1 = 8? + 2x 8'+3x8° Solution
=1x64+2x8+3x1 8 |9890 | R
=64+16+3
=83
8 | 1236
|2
8 | 154 | 4
8 | 19 | 2 Nowwrite the result starting from the
8| 2 | 3 _ last remainder obtained
Example 4.10 “|
0 12 Therefore, (9890), = (23242),
Convert (10567), into its decimal equivalent
Solution
Decimal number = 1« 8°+0x8'+5x8?+6x8'+7x8° 4.4.3 Converting an Octal Number into Binary
= 14096 +0*512+5*64+6x8+7x1 Form
= 4096 +0 +320+48+7 To convert an octal number into its binary equivalent,
=4471 replace cach octal digit with its binary equivalent,
The following steps summarize the procedure to convert an
octal number into a decimal number.
Example 4.13
Step 1; Start with the least significant digit and multiply
that digit with 8°. Note that any number raised to 0 Convert (63), into its binary equivalent
is always 1,
Solution
Step 2: Continue working from right to left. Multiply each
digit with an incremental power of 8 (i.e., 8°, 8”, 8°, (63), can be converted into its binary equivalent using the
8', etc.) following steps:

Step 3: Repeat Step 2 until all digits have been multiplied Step 1: Write the binary equivalent of 6, which is equal to
Step 4; Add the end result of each worked power of 8 to 110.
get the decimal number. Step 2: Write the binary equivalent of 3, which is equal to
011
Step 3: Merge the two values. Therefore, (63), = (110011),
Let us take another example and convert (175), Into its
4.4.2. Converting a Decimal Number into binary form.
Octal Form Step 1: Write the binary equivalent of 1, which is equal to
001
To convert a decimal number into its octal equivalent,
Step 2: Write the binary equivalent of 7, which is equal to
simply divide the decimal number by 8 and then write 111
down the remainder; repeat this process until it cannot be
Step 3: Write the binary equivalent of 5, which is equal to
divided by 8 anymore.
101
Step 4: Merge thevalues. Therefore,(175), =(001111101),
Example 4.11
4.4.4 Converting a Binary Number into Octal
Convert decimal 786 or (786);o into its octal equivalent
Form
Solution
8 |786 | R To convert a binary number into its octal equivalent, divide
the binary number into groups of bits, where cach group
8 | 98 | 2 consists of exactly three bits (except the last). Convert
Number Systems and Computer Codes 65

cach group into its equivalent octal number. Combine Case 2


these individual octal numbers to get the final result You can use the same concept while doing octal
addition. When we add two octal numbers there can be
two cases.
Example 4.14
Case |: The sum is less than 8. In this case, we just write
Convert (1101 100), into its octal equivalent the digit obtained after addition.
Solution
Case 2: The sum is greater than or equal to 8. In this case,
The steps to convert (1101 100), into octal form are as follows: 8 is subtracted from the sum and the result is
Step 1; Divide the number into groups of 3 bits each, written at that position, Moreover, a carry is given
starting from the LSB. Therefore, to the next digit
1101100 Consider the following examples
Step 2: Convert each group of binary bits into its equivalent
octal number. Thus, we have 15 4. | 4 3
Step 3: Merge the octal values to get the final result. Hence, |+3 #2
(1101100), = (154), | 7 5

Let us take another example and convert (10100110), into Case 1


its octal equivalent.
Step 1: Divide the number into groups of 3 bits each
|! :
| 14
Therefore,
10 100 110
\+27 c
43 1
Step 2: Convert each group of binary bits into its equivalent
octal number. Thus, we have 2 4 6. | Now, 4+7 in) Now, 5+7= 12
Step 3: Merge the octal values to get the final result. Hence, | which is greater than which is greater than
(10100110), = (246), 8. So subtract 8 from 8. So subtract 8 from
| 11, we get 3. Write 3 12, we get 4. Write 4
4.4.5 Adding Two Octal Numbers | at that position and at that position and
add a carry to the next add a carry to the next
How do you add two numbers in decimal? For example, |digit digit
when we add two numbers there can be two cases:
Case 2
Case 1; The sum is less than 10. In this case, we just write
the digit obtained after addition.
4.4.6 Subtracting Two Octal Numbers
Case 2 The sum is greater than or equal to 10. In this
case, 10 is subtracted from the sum and the result How do you subtract two numbers in decimal? For example,
is written at that position. Moreover, a carry is when we subtract two numbers there can be two cases:
given to the next digit Case 1: If the digit in the minuend is greater than the digit
4 3 in the subtrahend, subtract the digits and write the
+5 +2 result at that position.
9 5 Case 2: Ifthe digit in the minuend is smaller than the digit
Casel in the subtrahend, borrow | from the immediate
1 1 higher place. When a digit is borrowed, the
14 36 minuend digit at the current place gets 10 and 1 is
subtracted from the minuend digit at the immediate
+27 +48 higher place.
41 84

Now, 4+7=11 Now, 6+8= 14 | 9 8


which is greater which is greater |-5 6
than 10. So subtract than 10. So subtract | 4 2
10 from 11, we get 10 from 14, we get Case l
1, Write | at that 4. Write 4 at that
position and add position and add | 842 6 ¥4
a carry to the next a carry to the next 92 74
digit. digit 48 6 5
66 Computer Fundamentals and Programming in C

Since 2 is less than 8, Since 4 is less than 5, ones. Then, working from right to left, we move to a 16's
we borrow I from the we borrow | from the column, a 256’s column, a 4096's column, a 65,536's
next immediate digit. next immediate digit column, and so on. In programming languages, prefix ‘Ox*
So 9 now becomes 8. So 7 now becomes 6 is used to indicate a hexadecimal number,
Moreover we get 10, Moreover we get 10.
80 now it's not 2 but so now it’s not 4 but 4.5.1 Converting a Hexadecimal Number into
10 +2= 12. 8 is finally 10 +4 = 14. 5 is finally | Decimal Form
subtracted from 12 and subtracted from 14 and
the result is written. the result is written. To convert a hexadecimal number to decimal, multiply the
value in cach position by its hex weight and add each value
Case 2

You can use the same concept while doing octal Example 4.15
subtraction, When we subtract two octal numbers, there
can be two cases:
Convert 0x3128 into its equivalent decimal value.
Solution
Case 1: The digit in the minuend is greater than the digit
in subtrahend. In this case, we just subtract the Decimal number = 3 x 16° + 1x 167 +2 16° +B x 16°
digits and write the result. = 3x 4096 +1 256+2*16+Bx1
12288 +256+ 32+ 11
Case 2: The digit in the minuend is smaller than the digit = 12587
in subtrahend. In this case, borrow | from the
immediate higher place. When a digit is borrowed,
the minuend digit at the current place gets 8 and Example 4.16
4 | is subtracted from the minuend digit at the
immediate higher place Convert hexadecimal 123 into decimal.
Consider the following examples
Solution
98
3108
Decimal number = 1 x 167 + 2% 16'+3 «16°
7654 Arve =1x256+2*16+3x1
= 256 +32+3
2341 =3654
$313 0334 =291

——
4.5.2 Converting a Decimal Number into
G8 HEXADECIMAL NUMBER SYSTEM
Hexadecimal Form
The hexadecimal number system is the base 16 number To convert a decimal number into its hexadecimal
system. It uses sixteen distinct symbols—the symbols 0-9 equivalent, simply divide the decimal number by 16 and
represent values zero to nine, and A, B, C, D, E, F (or af) then write down the remainder, repeat this process until it
represent values 10-15, Figure 4.2 shows numbers from cannot be divided by 16 anymore.
0 to 15 and their values in binary as well as hexadecimal
number systems. Example 4.17
The main problem with binary numbers is that, for larger
values, binary numbers quickly become too unwieldy Convert decimal 1239 into its hexadecimal equivalent
The hexadecimal (base 16) number system overcomes Solution
this problem, as hexadecimal numbers are very compact
Moreover, it is very casy to convert from hexadecimal to 16 11239 | R
binary and vice versa. 16 | 77 | 7 Nowwrite
the result starting
from the last
In the hexadecimal system, just like in the binary, 16 | 4 | D_ remainder obtained. Therefore, (1239),o
octal, and decimal number systems, we start counting
from the first column, which represents the smallest unit, | 0 14 =(407):6

Figure 4.2. Hexadecimal number system and its binary and decimal equivalents
Number Systems and Computer Codes (a

Example 4.18 Step2: Write the binary equivalent of 1, which is


0001.
Convert (56789),, into its hexadecimal equivalent. Step 3: Write the binary equivalent of £, which is equal to
Solution 1110.
Step4: Merge the individual values. Thus, (A1E),_ = (1010
16 | 56789 |R
0001 1110).
16 | 3549 | 5 Step 5: Divide the binary number into groups of 3 binary
16 | 221 |D Nowwrite
the result starting from the bits. Therefore,
16 | 13 [0 fast remainder obtained. 101 000 011 110
Step 6: Convert each group of binary bits into its equivalent
| 0 | D Therefore, (56789), =(DDDS),. octal number.
Thus, we have 5 0 3 6.
Step 7: Merge the octal values to get the final result. Hence,
4.5.3 Converting a Hexadecimal Number into
(A1E)s6 = (5036).
Binary Form
=.
Figure 4.2 can be used to casily convert a hexadecimal
number into its binary equivalent. Simply break the binary Example 4.20
number into 4-bit groups beginning with the LSB, and Convert (680),, into its octal equivalent.
substitute the corresponding four bits in binary for cach
hexadecimal digit in the number. Solution
For example, convert OxABCD into its binary equivalent, Step 1: Write the binary equivalent of 6, which is equal to
From Figure 4.2, we have, (ABCD), = (1010 1011 0110.
1100 1101), Step 2: Write the binary equivalent of 8, which is equal to
Let us take another example and convert (F1E2),, into 1011.
binary, (F1E2),¢ = (1111 0001 1110 0010), Step 3: Write the binary equivalent of 0, which is equal to
0000.
4.5.4 Converting a Binary Number into Step4; Merge the individual values. Thus, (680),, = (0110
Hexadecimal Form 1011 0000).
Figure 4.2 can also be used to convert a binary number Step 5: Divide the binary number into groups of 3 binary
into its hexadecimal form. The first step is to pad the bits. Therefore,
binary number with leading zeroes (if necessary), so that 011 010 110 000
it contains multiples of four bits. Step 6: Convert each group of binary bits into its equivalent
For example, let us convert the binary number octal number. Thus, we have 3 2 6 0.
01101110010110 into its hexadecimal equivalent. Step 7: Merge the octal values to get the final result. Hence,
Note that the given binary number contains 14 bits. Pad (680),¢ = (3260).
the number with two zeroes on the left so that the number
———-_
has 16 bits (multiple of 4 bits).
Now, the binary number = 0001 1011 1001 0110. 4.5.6 Converting an Octal Number into
The next step is to look up these binary values in
Figure 4.2 and substitute the appropriate hexadecimal Hexadecimal Form
digits. The equivalent hexadecimal number = 1B96. To convert an octal number into its equivalent hexadecimal
number, first convert the octal number into its binary
4.5.5 Converting a Hexadecimal Number into equivalent and then convert the binary number into its
Octal Form hexadecimal form.
To convert a hexadecimal number into its octal equivalent, Example 4.21
first convert the hexadecimal number into its binary
equivalent. Then, convert the binary number into its Convert (567), into its hexadecimal equivalent.
equivalent octal number. Solution
The steps to be performed to convert (567), into its
Example 4.19 hexadecimal equivalent are as follows:
Step 1: Write the binary equivalent of 5, which is equal
Convert (A1E),, into octal form.
to 101.
Solution Step2: Write the binary equivalent of 6, which is equal to 110.
Perform the following steps: Step3: Write the binary equivalent of 7, which is equal to
Step1: Write the binary equivalent of A,which isequal to 1010. 111.
Computer Fundamentals and Programming in C

4: Merge the individual values. Thus, (567), = (101 Case 2: The digit in the minuend is smaller than the digit
110 111);. in the subtrahend. In this case, borrow | from
: Divide the binary number into groups of 4 binary the immediate higher place. When a digit is
bits. (Left pad the binary number
with zeroes if there borrowed, the minuend digit at the current place
are not enough bits to be grouped.) Therefore, gets 16 and a | is subtracted from the minuend
0001 0111 0111 digit
atthe immediate higher place.
Convert each group of binary bits into itsequivalent 15 23
hexadecimal number. Thus, we have 1 7 7. D218 16 EM1I7 7728
Merge the octal values to get the final result. Hence, 6A7B EASO FerD Exe
(567)s = (177)is. 2361 3 A87 -9 676 B3AD
471A ABO9 5 9A7 34DF
Example 4.22
WORKING WITH FRACTIONS
Convert (134), into its hexadecimal equivalent.
Solution In general, for a fractional number a, in any number system
Step 1; Write the binary equivalent of 1, which is equal to of base 4, the position values can be written as:
001.
Step 2: Write the binary equivalent of 3, which is equal to
011.
Step 3: Write the binary equivalent of 4, which is equal to The generalized table when used with specific base
systems can be given as in Table 4.7.
100.
Now let us use Table 4.7 to convert the following
Step 4: Merge the individual values. Thus, (134), = (001
numbers of base 6 into decimal.
011 100),.
Step 5: Divide the binary number into groups of 4 binary 1. Convert (101101110), into decimal:
bits, Therefore, (10110.1110))
=1 *28+0x 2+ 1x 2+1%2'4+0%
0000 0101 1100 Peixrterx2+ 1x 2940x294
Step 6: Convert each group of binary bits into its equivalent = 1X 1G+OKR+1 KAHL 2+OK1+
hexadecimal number, Thus, we have 5C. LX U2+ 1K 14+ 118 +0% 1/16
Step 7: Merge the hexadecimal values to get the final =16+0+4+2+0+05+0.25
+0.125+0
result. Hence, (134), = (5C)
x5.
= 22.875
2. Convert (127.35), into decimal:
4.5.7 Adding Two Hexadecimal Numbers (127.35), = 1 * 8 +2%8'+ 7% 8943x8445 x87
You can add two hexadecimal numbers in the same way
= 16442847143 «145% 1164
as you add decimal and octal numbers. When we add two
= 64 + 16 + 7+ 0.375 + 0.078125
hexadecimal numbers, there can be two cases: = 87.453125
Case 1; The sum is less than 16, In this case, we just write 3. Convert (21 F.DE))« into decimal:
the digit obtained after addition. (QQIR.DE),
5=2* 167+ 1* 16'+F * 16°+D x 16" +
Ex 167
Case2: The sum is greater than or equal to 16. In this =2*256+1* 16415 *1413 *16+
case, 16 is subtracted from the sum and the result 14 * 1/256
is written at that position. Moreover, a carry is =S512+ 16+ 15 +0,8125 + 0,0546875
given to the next digit. = 543.8671875
Consider the following examples:
Now that we have converted a fractional binary/octal/
1 111 111 hexadecimal number into its decimal equivalent, let us learn
1A2B 2C4A 5C8D 6E8C how the fractional part of a decimal number can be converted
+2361 +D287 +9676 +B3AD into its equivalent binary/octal/hexadecimal number.
3D8C FEDI F303 12239
Example 4.23
4.5.8 Subtracting Two Hexadecimal Numbers
Convert the decimal number 92.25 into its equivalent binary
When we subtract
two hexadecimal
numbers there can be number.
two cases: Solution
Case 1: The digit in the minuend is greater than the digit Break the number into two parts. The first part consists
of digits
in the subtrahend. In this case, we just subtract the before the decimal point, and the second part contains digits
digits and write the result. after the point. A separate procedure is applied to convert
Number Systems and Computer Codes 69

Loa Position values of digits in various number systems

Position 5 4 WE: ! 0 wf, | <a | od | 26 | a8


|Position value in decimal 10° «10° 10° 10 10 10" 10% 10% 10%
Position value in binary 2 ES ee a FE) a) Ea) ee iat
| Position value in octal oy (RS) ES] Ee ie 5 AST eS ee
\Position value inhexadecimal 16° 16¢ 16" 16° is 16°16" 167 16? 16 16%)
these individual parts of the decimal number into binary. While Example 4.25
the whole number part (before the decimal) is converted using
repeated division by 2 and considering the remainders, the Convert the decimal number 12345.48 into its equivalent
fractional part on the other hand, is converted by repeated hexadecimal number.
multiplication with 2 and considering only the whole number Solution
part of the result, Figure 4.3 clarifies this concept Figure 4.5 shows the conversion process.
Number
Whole number part Fractional Number = 12445
2) 92)R 0.25 Whole number = 12345 Fractional =048
2/46/00 2 16 |12345 |R 048
212310 0.50 16] 771 |9 x16
2|it zs 16] 48 |3 7.68
215 [1 1,00 16] 3 Jo x16
21211 a 3 ABS
2) 1}0 0.00 (12345),, = (3039), 216
ofl 0.25)»
=(0.010), Note down the remainders B08
(02),, = (1011100), Note the digit before the starting from the last x16
Note down the remainders) decimal point obtained remainder obtained. 1.28
starting from the last from the first (0.48), = (O.7AEL),,
obtained, multiplication to the last.
Hence (02.25), = (011100010), Note the whole number
part of result obtained
Fig.4.3 Conversion of a decimal number to its from the first
equivalent binary number multiplication to the last.
(12345.48), = (3039.7AE1),,
Example 4.24
Fig. 4.5 Conversion of a decimal number to its
Convert the decimal number 178.92 into its equivalent octal equivalent hexadecimal number
number,
Solution
Figure 4.4 shows the conversion process. SIGNED NUMBER REPRESENTATION
[ Number = 178.92 IN BINARY FORM
Whole number part
=178 Fractional part = 0.92
BII78|R 0.92 Signed number representation is required to encode
x8 negative numbers in the binary number system. Basically,
8] 22)2
the negative numbers in any base system are written by
8| 2|6
preceding the number with a~sign (minus sign), However,
ol2 in computers, negative numbers too are represented
(178),, = (262), in binary. The binary language, which the computer
Note down the remainders understands, does not support the minus sign to write
starting from the last negative numbers.
92),, = (0.7270),
remainder obtained. Hence, a different technique is required to encode the
Note the whole number minus sign in terms of 0s and Is. There are three widely
part ofthe result obtained used techniques for extending the binary number system to
from the first
multiplication to the last. represent signed numbers. These techniques are sign-and-
Hence (178.92), = (262.7270), ] magnitude, one’s complement, and two's complement.
Out of the three, the two's complement method is the most
Fig. 4.4 Conversion of a decimal number to its popular for representing signed numbers in the binary
equivalent octal number number system.
70 Computer Fundamentals and Programming in C

4.7.1 Sign-and-magnitude In two's complement —54 can be given as:


Binary representation of +54 is 0011 0110.
Sign-and-magnitude is the simplest technique in which the Complement each bit: 1100 1001
most significant bit (MSB) is set to 0 for a positive number Add I to this result. Therefore,
or zero, and set to | for a negative number. The other bits
denote the value or the magnitude of the number 11001001
Hence, a byte having cight bits can use only seven bits +1
to denote the magnitude, and one bit is used to denote the 1100 1010 (-S4 in two's complement)
sign of the number. Using 7 bits, numbers from —127 to The main advantage of using two's complement is that
+127 can be represented (i.c., 2’ combinations). there is only one zero (0000 0000). For example, when
For example, consider Table 4.8 which illustrates how signed converting —0 in two's complement form, complementing
numbers are represented using sign-and-magnitude method. the bits gives IIIIIII1 and adding | gives 0000 0000
and a carry bit of 1. When we add numbers in two's
Representation of signed numbers in sign- complement, we discard the carry from the last bit. Hence,
and-magnitude method the result is only 0000 0000
Binary equivalent in sign-and-magnitude form
Decimal
Decimal Tsien] 7™ |6 |s® |]a®] a¢ |=| a
Similar to the one’s and two's complements, there is also
bit | bit | bit | bit | bit | bit | bit | bit
nine’s complement and ten's complement.
| 436 7 On (AT) GON Lee Se ee we To find the nine’s complement of anumber, subtract
| -4s Sal Fe EET RG ES FS (SP cach digit of thenumber from 9. Forexample, the nine’s
esi OS GH EE a aT A (RE complement of 12345 is 87654.
\ 108 iy TAT) (Eee) [Sey] Peel as bw Tofind the ten’s complement of a number, first find the
nine’s complement of that number and then add 1to it.
For example, let us find the nine’s and ten’s
4.7.2 One’s Complement complements of 314700.
The one’s complement representation of a negative Nine’s complement = 685299 and ten’s complement=
number is obtained by taking the complement of its 685300.
positive counterpart (in binary). For example, if one wants
to represent —45 in the binary number system using one’s
complement method, then perform the following steps CEB scp cope
* Write the binary representation of the number's positive Binary coded decimal (BCD) is a very simple technique
counterpart, that is, write the binary equivalent of +45, used for encoding decimal numbers, In this scheme,
* Negate cach bit in the binary representation of the digit is represented by its own binary sequence. The main
positive number (+45 in this case). advantage of using BCD is that it allows casy conversion
to decimal digits for printing or display, and allows faster
So, +45 in binary form is 0010 1101. Now negate cach bit
decimal calculations.
to obtain the binary representation of —45.
Consider Figure 4.2 in which the binary representation
Hence, —45 in binary = 1101 0010
of numbers 0-15 is shown. In BCD representation the digits
The PDP-1 and UNIVAC 1100/2200 series use one’s
0-9 are used. Each decimal digit (0-9) is represented by
complement arithmetic, The range of signed numbers that
four binary digits. For example, decimal 7 =0111 in BCD.
can be represented using one's complement in a byte is There are two types of BCD numbers—packed BCD and
from ~127)9 t0 +127).
unpacked BCD.
In unpacked BCD representation, only y one decimal
4.7.3 Two's Complement digit is represented per byte. The digit is stored in the
In one’s complement method, +0 is represented as lower nibble, and the higher nibble is not relevant to the
00000000 and —0 is represented as 11111111. In sign-and- value of the represented number. For example,
magnitude method, -0 is represented as 10000000. These Decimal 17 0000 0001 0000 0111 (in BCD)
different representations sometimes become problematic ;
Therefore, to avoid such a situation, the two's complement 1 7
representation is generally used. This representation is
Hence, to convert a decimal number into an unpacked
obtained in the following two steps:
BCD number, assign cach decimal digit, its 8-bit binary
* Complement or negate the bits in the binary equivalent.
representation of the positive number. In packed BCD representation, two decimal digits are
* Add 1 to the result of the first step. stored in a single byte, For example,
Number Systems and Computer Codes {£)

Decimal 17 = 0001 0111


ee
(in BCD)
CED otter coves
E ‘7
In this section, we will read about other coding techniques
Hence, to convert a decimal number into a packed BCD that arewidely used toconvert data into the form of 0sand Is.
number, assign to cach digit of the decimal its 4-bit
equivalent, padding the upper nibble with zeroes. if 4.9.1 ASCII Code
necessary (in case it is required to write a byte value rather
than a nibble value). For example, ASCII stands forAmerican Standard Code for Information
Decimal 7 = 0111 (in packed BCD) or 0000 O111 (in Interchange. It is a 7-bit character
code (refer Figure 4.6) that
packed BCD, if padding is required). was introduced by the American National Standards Institute
To convert a number from BCD to decimal, just reverse (ANSD) and is used by personal and workstation computers,
the process, that is, perform the following steps: ASCII characters are examples of unpacked BCD
numbers. Values in ASCII codes are represented as their
+ Start with the least significant byte. 4-bit binary equivalents stored in the lower nibble, while
* Group the binary digits into groups of four if it a packed the upper nibble contains 011 and has no bearing on
BCD number, otherwise in groups of eight bits if it is an the value of the represented number. ASCII is the most
unpacked BCD number, common format for text files in computers and on the
* Convert each set into its decimal equivalent. Internet. It can define 128 different characters because it is
For example, consider the packed BCD number, 0010 4 7-bit code, and can support 2’ combinations, The various
1001, Convert it into its equivalent decimal number. Now, ASCII characters are listed in Figure 4.6.
in the number, identify the LSB to start with. So, 0010
1001,sq.Group the binary digits into sets of four because 4.9.2 Extended Binary Coded Decimal
the number is in packed BCD format. Interchange Code
aZz 93
0010
Extended binary coded decimal interchange code
(EBCDIC) is an 8-bit character-encoding technique used
Hence, the decimal equivalent of the packed BCD number on IBM mainframe operating systems. It supports a wider
0010 1001 = 29, range of control characters than ASCII because it supports
Now, let us discuss another example, Consider the 8-bit character codes that can encode 2" or 256 characters.
unpacked BCD number, 0000 0011 0000 0110, Convert EBCDIC is easier to use on punched cards, Although
it into its equivalent decimal number. Now, in the number, it is considered to be an obsolete coding system, it is still
identify the LSB. So, 0000 0011 0000 0110, 69. Group the used in some equipment, to allow for continued use of
binary digits into sets of eight because the number is in software written many years ago that requires an EBCDIC
unpacked BCD format. communication environment.
EBCDIC characters are similar to ASCII characters.

a While the lower nibble contains the 4-bit binary equivalent


(as in ASCII), the upper nibble on the other hand is padded
with 1111, instead of O11.
Hence, the decimal equivalent of the unpacked BCD
number 0000 0011 0000 0110 = 36. 4.9.3 Excess-3 Code
The following are the advantages and disadvantages of
In the excess-3 (XS3) coding method, cach decimal digit
BCD codes:
is the 4-bit binary equivalent with 3 (0011) added.

Advantages 4.9.4 Weighted Codes


* Similar to decimal number system
* You must remember binary equivalent of only 0-9 In weighted binary codes, cach position of the number
decimal numbers represents a specific weight. For example, we have 8421,
2421, 5211, and 4221 codes.
* It is easy to use BCD codes for input and output
operations in digital systems.
8421 BCD Code
Disadvantages BCD codes are also known as 8421 codes because each of
* BCD addition and subtraction has different rules the four bits is given a *weighting’ according to its column
* BCD arithmetic is more complex than binary arithmetic value in the binary system. The LSB has the weight or
* BCD is less efficient than binary numbers because it value 2° = 1, the next bit has value 2' = 2, the next bit has
requires more number of bits to store the same decimal value 2? = 4, and the MSB has the value 2) = 8, as shown
number in Table 4.9.
Fundamentals
and Programming in C

Dec HxOctChar Dec Hx GetHtml Che


0 0.000 NUL (ally 32:20 040 432 Space |6440 10D Ase @ =| 96 60 140KN,"
1 1 001SOH (startofheading) 3321 041 33,1 6541 LOLAES. 4 97 OAL HO? a
2 2,002 STX (start oftext) 34 22042 Ae, ~ (6642102 £966. B 88 62142 HIRD
3 3003 TX (end oftex) AS DOES AHS. 67.43 103 £967. 99 6S143N99. €
4 4.004 BOT (end oftransmission) OH AES 68 44108 £968. 100 64144 NEO
S $.005 ENQ (enquiry) 37 28085 A937: 45 WS £O6). E 1OL 6S 145 KMIOL ©
6 6 006 ACK (acknowledge) 38 26046 AOS, & W046 106 £870. F 102 66 146W102: 1
7 7 007 BEL (bell) 3927 O87 Reo.” 71.47 107 &e7.G 10S 67 147 HW103.
8 8010 BS(hackspace) 40 250180 8H: ( 7248 10 R072 1k 6 150 104 by
9 9.001 TAB (herrizental
tats) 41 29051 aesl:) 7349 TL RATS. 10S69181 GMTOS. i
10 A012 LFUNL bine feed. new line) 422A 082 aed 4A 12 aed 106 GA 1ST &H106, 5
11.B O13 VT (wemcal tab) 43:2B O83 kee TSAB LIS ASTS. KK 107 GE ESS A107
12.C 014 PF(NP frm feed, mew page) | 44 20-054 eee, | HAC 14 &eTe OR OC ES em1OH IL
13 D OFS CR (carriage retam) 45 2DOSS WHS, - TT AD LES &77. M 109 6D 15S #109,mm
14 B O16SO (shaft owt) 46 2B OS Be, ‘TS4E 116 ROT 110 68 156 Rat On
ISP O17 St(shift way 47 POST weet. / TO4P 117 £879, 0 111 OF157 att 1.0
16 10.030 DLE (datalinkexcape) 45 00080 £48, 0 850 13) een. P 11270160AMEND. p
17:11.021 DCI (device comtrot 1) 47 31 061 aeay. 1 ‘SUSE 121 ean.Q TAS71161GML. g
18 12.022 DC2 (device comtrot 2) $0 32062 ASO, 2 HL 12 AK $14 72162 Reta
19 13.023 DCS (device contrat 54 $1: 33063 east. s ‘8553 125 AeRd, S HES TS 163 MATES: ©
20 14.04 DCA (device comtrot 4) S234 064 aeS2.4 454 124 aOR T 11674164RHEL
21.15 02S NAK (negative ackawtedge) | $3.38
065 AWS: 5 5555 125 AAS. LIT 7S165 QW? @
22 16036 SYN (symchromous ithe) S456 086 BaSa, 6 80 56128 RON 118 76166det Ley
23.17 027 ETH (ond ofcrams Ihocky ‘SS 57067 aess, 7 5757 127 AO Ww 119 77167 dew bh we
24 IROOM CAN (cancel) $6 38070 Awe, & ‘8s58 10 EX 120-78170 WLIO ©
25.19.091 EM (ondofmedium) ST.9071 est. 8959 101 BAY 128-70
171 andy
261A O82 SUB {subsuitute) SS MAOT? Aeon, WOSA TN a Ze 122 7A 172 RH
TT 1B O38 ESC (escaped 9 OTS BEM, 9 SB LSS Ae | 128 7H ETS RAIDS,
261C OM ES(ikeseparator) 6010 04 kata, < 1s 7e174anal
20 1DO45 GSigroup separator) 61 1DOFS APO, = 125-71)
17S sends)
30 1E.056 RS (rocerd separation) 62 32076 A002. > 126 TE 176 ew 26 ~
SLIP OS? US @ i 127,78
177 aqiz? DEL.

Convert 4567), to BCD 2.5. Give the BCD equivalent for the decimal number 68.23.
Solution Solution
From Table 4.9, we can write, From Table 4.9, we can write,
{4567)
x =(0100 0101 0110 0111) scoser: {68.23),9
=(0110 1000.0010
0011Jecpes2t
Number Systems and Computer Codes e

4.8.6 Unicode
ASCII, which is the most widely used encoding scheme, is
a 7-bit code that can support only 128 character definitions.
These 128 characters can be used casily for English
characters, numbers, and punctuation symbols but there is
2421 Code negligible or no support for the characters in other languages
of the world. Therefore, organizations started creating their
The 2421 weighted code has weights 2, 4, 2,and 1. In own encoding schemes for other languages’ characters,
this code, a decimal number is represented using 4 bits. thereby defeating the concept of a universal or standard code
The maximum weight in this code is2+4+2+1=9, for information exchange. Moreover, each new scheme was
Therefore, the 2421 code can represent decimal numbers of different length, and programs were supposed todetermine
from 0 to 9, as shown in Table 4,10. which encoding scheme they would be using.
Similarly,
in the 4221 coding. each digit isrepresented The only solution to this problem was to have a new
as a 4-bit group, and cach bit represents 4, 2, 2, and 1, encoding scheme that could unify all the different encoding
instead of 8, 4, 2, and 1. For example,7 in 4241 can be schemes to minimize confusion between the different
written as 1101, because 1 *4+1*2+0*%2+1*1=7. schemes. This led to the development of Unicode, which
can represent characters (including punctuation marks,
4.9.5 Gray Code diacritics, mathematical symbols, technical symbols, and
The gray code is a minimum change code, in which only arrows) as integers. It has several character encoding
one bit in the code changes from one code to the next. It forms such as the following:
is a non-weighted code. These codes are also known as UTF-8 Thisuses only eight bits t encode English characters.
single-distance codes. This format iswidely used inemail and onthe Intemet.
‘The gray code of a number is obtained from its binary UTF-16 This uses 16 bits to encode the most commonly
code, To derive the gray code of a number, the following used characters.A 16-bit Unicode can represent more
steps are used: than 65,000 characters. Moreover, any Unicode character
+ Copy the MSB of the binary code as the MSB of the represented in the UTF-16 form can be converted to the
gray code, UTF-8 form and vice versa without losing information.
* Repetitively add MSB and the bit next to the MSB to UTF-32 This uses 32 bits to encode the characters.
get the correspondingbit for the gray code. A 32-bit Unicode can represent more than 100,000
For example, letuscalculate the gray code of 7. characters.
Decimal
7=Binary 0111
Now gray code of 7 is obtained as follows:
* MSB of gray code 7 is 0 (because MSB of binary 7 is 0)
Now, other bits can be calculated
© O0+1=1
as:
Da ET
Besides representing the characters of different
+ 1+1 =0(discard the carry) languages, UTF also reserves some codes for private
+ L+1=0 (discard the carry) use, which hardware and software vendors can assign
Hence, gray code for 7 = 0100. internally for their own characters and symbols.
74 Computer Fundamentals and Programming in C

Nowadays, Unicode is widely used to represent text for computer processing, as it provides a consistent way of
encoding multilingual characters. This makes it convenient to exchange text files internationally. The growing popularity
of Unicode suggests that it will eventually supplant ASCII as the standard coding scheme.
Table 4.11 illustrates how coding is done in the ASCII, EBCDIC, XS3, 4221, gray, and Unicode coding techniques.

eee Decimal number represented in different codes


Digit Binary ASCII EBCDIC XS3 4221 Gray code Unicode
0 0000 0011 0000 1111 0000 ool ‘0000 1000 U +0030
1 0001 0011 0001 1111 0001 0100 0001 OOK U+0031
2 0010 0011 0010 1111 0010 o101 no10 ool U +0032
3 oO1L O11 OO11 11110018 ono oor 0010 U +0033
a 0100 0011 0100 1110100 ol 1000, O10 U+ 0034
s olor oo 0101 ti) o1or 1000 out Ont U +0035
6 ono OO11 0110 M1010 1001 1100 O1oL U+ 0036
7 oll ool OLE PeERRURLT 10 1101 0100 U +0037
& 1000 0011 1000 1111 1000 wn Ho 1100 U +0038
9 1001 OOLT 1001 1111 1008 1100 tit 110k U +0039

POINTS TO REMEMBER
* Computers are electronic machines that operate using Binary coded decimal (BCD) is a technique of
binary logic. These devices use two different values to encoding decimal numbers. In unpacked BCD
represent the two voltage levels (OV for logic 0 and SV representation, only one decimal digit is
for logic 1). represented per byte. In packed BCD representation,
* The number of unique digits used to form numbers two decimal digits are stored in a single byte.
within a number system is called radix of that system. ASCII is a 7-bit character code that was introduced
Decimal number system has a radix of 10, binary has a by ANS! and is used by personal and workstation
radix of 2, octal has a radix of 8, and hexadecimal has computers.
a radix of 16. EBCDIC is an 8-bit character encoding technique used
To convert a decimal number into its binary/octal/ on IBM mainframe operating systems. It is considered
hexadecimal equivalent, simply divide the decimal to be an obsolete coding system, but Is still used in
number by 2/8/16 and then write down the some equipment to allow for continued use of
remainder, software written many years ago that requires an
To convert a binary/octal/hexadecimal number into EBCDIC communication environment,
its decimal equivalent, multiply the place holder * In the excess-3 coding technique, each decimal
value by the digit, and then add all the products. digit is the 4-bit binary equivalent with 3 (0011)
Signed number representation is required to encode added.
negative numbers in the binary number system. * Gray code is a minimum change code, in which only
* The two’s complement is the most popular method ‘one bit changes from one code to the next.
of representing signed numbers in the binary
number system.

GLOSSARY
Binary number system It is a number system of base 2 Hexadecimal number system It is a number system of
Bit It is short form of ‘binary digit’; smallest possible unit base 16.
of data; can be either 0 or 1. Nibble It is a group of four binary digits.
Byte It is a group of eight bits. Octal number system it is a number system of base 8,
Decimal number system It is a number system of base 10. Word It is a group of 2 bytes.
Number Systems and Computer Codes 75

EXERCISES

Fill in the Blanks 10. Computers can define a word of four bytes.
1, Computers are electronic machines that operate on
logic. Review Questions
2. bits make one word, 1. What is binary language?
3.0-1 =_ -_ 2. Why do computers understand only binary language?
4. Inthe _____ technique, the MSB is used to denote 3. Explain the process of converting a binary number into
the sign of the number. decimal with an example.
5. In , the digit is stored in the lower nibble, and Describe the general procedure to convert a number
the higher nibble is not relevant to the value of the from any base system into its decimal equivalent. Explain
represented number. using examples the conversion of numbers from any
6, ASCII codes can support characters. three base systems to the decimal system.
7, EBCDICisa__ bit character encoding technique. How can two numbers be subtracted only through
8. The hexadecimal number system uses digits from addition? Explain with the help of an example.
to How are signed numbers represented in the binary
9. The octal number system was used in the _ form?
system. Two's complement is the most popular technique to
10, Working from right to left, the colurnns in the hexadecimal represent signed numbers. Justify the statement.
number system are Differentiate between packed and unpacked BCD
representations.

Multiple-choice-Questions How is the 8421 code different from the 4221 code?
1. The code that is easier to use on punched cards is Give the gray code for the decimal number 13
(a) ASCII (b) EBCDIC Convert the following numbers into the decimal number
system.
(c) Excess-3 (d) BCO
2, The code also known as single-distance code is {a) (1011 0101),
(a) ASCIL (b) EBCDIC (b) (5674),
{c) Excess-3 (d) gray code {c) (A1E2),6
3, The coding technique in which the upper nibble is {d) 0000 1001 (unpacked BCD)
padded with 1111 is (e) 1000 0001 (packed BCD)
(a) ASCII (b) EBCoIC Convert the decimal 987654 into octal and hexadecimal
number systems.
(c) Excess-3 (d) gray code
4, 12345 in octal is_ in decimal. Convert 1001 0010 1110 into the hexadecimal number
system.
(a) 5439 (b) 5349 Convert 89CD into the binary number system.
(c) 4593 (d) 4359 Subtract:
5, 98765 in decimal is in hexadecimal
(a) 10101011 -01111
(a) 1¢81D (b) C1810
(b) 11100001 ~ 11110111
(c) 181¢D (d) C0181
{c) 1010101010 ~ 111101
16. Add:
State True or False
1, Abyte is a group of eight bits. (a) 10101011 + 0111111
2, Bits 4 through 7 form the lower nibble. (b) 11100001 + 1121110111
3. l+1=1 {c) 1010101010 + 111101
4. The two's complement method can be used to 17 Multiply:
restructure a subtraction as an addition problem. (a) 10111 x 1011
. The octal number system uses digits from 0 to 8. (b) 1111000 100
au
. The two's complement of a negative number is obtained
(c) 1121101 * 1111
by negating the bits of its positive counterpart.
18. Divide:
7, In packed BCD representation, two decimal digits are
(a) 10121110/1011
stored in a single byte.
8, ASCII digits are examples of unpacked BCD numbers. (b) 1111000/100
9. ASCII supports more number of characters than EBCDIC. (ec) 1121101301/1111
Boolean Algebra and
~~ ‘Logic Gates
TAKEAWAYS
© Boolean algebra © Truth tables © Universal gates
¢ Venn diagrams * Canonical forms * Karnaugh
map (K-Map)
* De Morgan's
law © Logic gates

The proposition can be represented diagrammatically


8B BOOLEAN ALGEBRA as shown in Figure 5.2
As already discussed in Chapter 4, computers understand
only binary numbers, in which only the digits 0 and | are Get admission
used. These binary computer systems work on propositional in MSe
OR
logic, wherein a proposition may be true or false and may Get admission
also be stated as functions of other propositions that are in MCA
UJ
connected by three basic logical connectives—AND, OR, ARDS Do post-
and NOT, For example, graduation
1 will do postgraduation if 1 get admission in MSc or
MCA
This statement functionally connects the proposition Geta job NOT
‘I will do postgraduation’ to two propositions—‘if 1 get
admission in MSc’ and ‘if | get admission in MCA’. This
scenario can be represented as shown in Figure $3.1 Figure 5.2 Statement and complex propositions

Thus, we see that a complex proposition can be casily stated


Get admission
in terms of binary (two) variables and binary operators (OR,
in MSe Do post
~ graduation AND, and NOT). Itis for this purpose that the mathematician
Get admission George Boole developed Boolean algebra in 1854.
in MCA In Boolean algebra, a Boolean system has either of two
Figure 5.1 Statement and simple propositions states—true (T) or false (F). The following are the salient
points of Boolean algebra
From this discussion, we can conclude that the meaning + Value *1* means true.
of the OR connective is that the corresponding output * Value °0’ means false.
is true if either one of the inputs is true; otherwise, it is * A Boolean expression is a combination of Boolean
false variables and Boolean operators. Boolean expressions
We can make this proposition a little more complex that are logically equivalent to one another are called
by saying “I will do postgraduation if 1 do not get a job equivalent expressions.
and if 1 get admission cither in MSc or in MCA’. Before * A Boolean function bas one or more input variables and
preparing the block diagram for this preposition, we must generates an output based on these input values, The
first state it in a well-structured way to understand how it result may be 0 or 1
is composed. The proposition can be given as follows: * Boolean operators take certain inputs and produce an
Do postgraduation = (NOT (Get a job)) AND ((Get output based on a predetermined table of results (also
admission in MSc) OR (Get admission in MCA)) known as the truth table).
Boolean Algebra and Logic Gates 7

* The Boolean operator AND (conjunction or intersection) Absorption


Law: x > (xy) =x
is used as a *." and in some texts as *4". For example,A -
Bor A B meansA andB. The ANDoperator takes two Shade the portion forxUy. Next, shade the portion forx,
(or more) inputs and returns a 1 only when both (or all) Then, shade the area that is common in both the diagrams.
inputs are I, The resultant shaded area will be the whole of the circle x
* The Boolean operator OR (disjunction or union) is used (Figure 5.4).
as a ‘+’ and in some texts as “n". For example, A + B
or A U B means A or B. The OR operator takes two
(or more) inputs and returns a 1 when any or all of the
inputs are 1,
* The Boolean operator NOT (negation) is used as “" and
in some texts as “~’. It simply negates the value of the auy
operator. For example, A' means NOT A. If the input is Figure 5.4 Venn diagrams for absorption law
1, the output will be 0 and vice versa.
Boolean algebra forms the basis of digital systems. It is Double Negation
Law: (x')' = x
extensively used to design digital circuits and is applied
First, shade the circlex.Then, shade the area not in.x. This
in digital logic, computer programming, set theory, and will give the region for x’. Next shade the area that is not in
statistics.
x’, which will be the whole of circle x (Figure 5.5).

VENN DIAGRAMS
A Venn diagram can be used to represent Boolean
operations using shaded overlapping regions. In the Venn x
Yi, x wy
diagrams that are presented in this section, there is one
Figure 5.5 Venn diagrams for double negation law
circular region for cach variable, The interior and exterior
of aregion ofa particular variable corresponds to values 1
(truce) and 0 (false), respectively, The Venn diagrams De Morgan’s
Law: x Oy’ =(x Uy)’
corresponding to AND, OR, and NOT operations are To visualize De Morgan's law, for the left-hand side
shown in Figure 5,3. Here, the shaded area indicates the (LHS), shade the area that is neither in x nor in y. Then, for
value | of the operation and the non-shaded area denotes the right-hand side (RHS), shade the area corresponding to
the value 0, x Uy, which is the area in eitherorboth the circles, Finally,
shade the area that is not in the region of x U y. It canbe
seen from Figure 5.6 that it is the same area that we had
shaded for the LHS.

voy vuy 7 Y
Figure 5.3 Venn diagrams for conjunction (AND),
disjunction (OR), and complement (NOT) ay ny
ZY
Yt
avy leayy
The following points can be observed from Figure 5.3: Figure 5.6 Venn diagrams for De Morgan's law
* For the AND operation, the region common to both
circles is shaded to indicate that x 9 y is | when both
variables are 1, The non-shaded area indicates that x Oy
is 0 for the other three combinations of variables x and y.
TRUTH TABLES
* For the OR operation, the regions that lic inside eitheror
A truth table is used to describe a Boolean function of
both the circles are shaded.
n input variables. It lists all possible values of input
* For the NOT operation, the Venn diagram represents combinations of the function and the output that will
complement x’ by shading the region nof inside the be produced based on these input combinations. Such
circle,
a table provides a useful visual tool for defining the
Venn diagrams are useful to understand and visualize the input-output relationship of binary variables in a Boolean
following laws of Boolean algebra. function.
78 Computer Fundamentals and Programming in C

A Boolean function of'n variables has 2" rows of possible term OR’ed with a | is always | and a term AND‘ed with
input combinations, Each row specifies the output of the a 0 will always result in 0.
Boolean function for a different combination. The truth |. A+0=A
tables for the Boolean operators are shown in Table 5.1 If A = 0, then 0 + 0 = 0, which is equal to A
If A = 1, then 1 +0 = 1, which is again equal to A
Lee Truth tables for Boolean operators 2. At+1=1
| AND OR NOT IfA =0, then 0+1=1
\| a [z=A.8 | 4 |B |Z=AsB 4 |Z=a IfA= 1, then 1 +1=1
jo 0 oy) ww 0 on 8 3. A-0=0
}o a oO” me 1 1 0 IfA = 0, then 0-0 =0.
IfA= 1, then 1 0=0.
|i @ om) Wwe 1
WEEE i Gl 1 4. A*1=A
IfA= 0, then 0+ 1 0, which is equal to 4
IfA=1,then ts 1 1, which is again equal to A
A truth table can also be used to represent one or more
Boolean functions, For example, Table 5.2 represents the 5.4.2 idempotency Law
truth table for the Boolean function Z= 4 U(B OC).
The idempotency law states that a term AND’ed with itself’
or OR’ed with itself is equal to that term
Truth tableforBoolean function 2= AU (8) 1. A+A@A
A la c Ipnc |ZuAs(BUq) If A = 0, then 0 + 0 = 0, which is equal to A
0 0 ) ° ° IfA = 1, then | +1 = 1, which is again equal to A (here,
A + B means a true valuc, that is, a non-zero value),
0 0 1 0 o
2. A*A=A
0 1 0 0 o IfA= 0, then 0° 0 0, which is equal to A
0 1 1 1 1
IfA=1,then ls 1, which is again equal to. A
1 0 0 ° 1
1 0 1 0 1 5.4.3 Complement Law
1 1 0 0 i The complement law states that a term AND'ed with its
\ 1 1 1 ! 1 comple-ment always results in 0 and a term OR'ed with
its complement always results in |
|, A+A'=1
23 Basic LAWS OF BOOLEAN ALGEBRA IfA= 0, thenO+1=1
IfAw@ 1, then 1 +01
The laws of Boolean algebra can be divided into two
2. A-A'=0
categories—laws applicable on a single variable and laws IfA=0, then 0-1 0, which is equal to 0,
applicable on multiple variables (Figure 5.7).
IfA=1, then 1-0 0, which is again equal to 0

Boolean algebra laws 5.4.4 Involution Law


The involution law, also known as the double negation
(Applicable onsingle variable} {Applicableonmultiple variables } law, states that a term that is inverted twice is equal to the
original term.
* Identity law * Commutative law
(AyY=A
* Idempotency law * Associative law
* Complement law * Distributive law If4 = 0, then (0’Y can be solved as I' =0, which is equal to A
* Involution law * Absorption law If = 1, then (1’Y can be solved as 0 = 1, which is equal to A
* Consensus law
+ De Morgan's law 5.4.5 Commutative Law
Figure 5.7 Classification of laws of Boolean algebra The commutative law states that the order of application
of two separate terms is not important
5.4.1 identity Law 1, A+B=B+A
The identity law states that a term OR’ed with a 0 or The truth table of the Boolean functions proves this law, as
AND’ed with a 1 will always equal that term. Similarly, a shown in Table 5.3
Boolean Algebra and Logic Gates 79

Truth table to prove the commutative law Truth table to prove the associative law
of the OR operator of the AND operator
A B A+s B+a A B c 4-(8-C) | (A- Bye
0 o 0 0 o 0 o o 0
0 1 1 1 0 0 1 0 0
1 0 1 i 0 1 0 0
1 1 1 1 o ' 1 0 0
1 0 0 o 0
i 0 ! 0 i}
2. A*B=B-A 1 1 0 0 0
Table 5.4 shows the truth table of the Boolean functions, 1 1 1 i 1
which proves this law

5.4.7 Distributive Law


Lee Truth table to prove the commutative law of
the AND operator The distributive law enables multiplication or factoring
A B A-B BA
out of an expression.
0 0 0 o L. AB+ OC) =A BAe’
0 1 o 0 The truth table of the Boolean functions, shown in
1 0 0 0 Table 5.7, proves this law
1 1 1 1

[Table 5.7]Truth table to prove the first distributive law


5.4.6 Associative Law A} BC) B+C) AUB4+O) | ASB IASC|ABHAC
The associative law allows the removal of brackets from 000 oO ) 0 0 0 |
an expression and regrouping of the variables. oot. 0 o 0 0 |
1, At+(B+C)=(A+B)+O i Es a) ee o o 06 0 |
The truth table of the Boolean functions, shown in mB) 0 0 0 0 |
Table 5.5, proves this law 1oo 0 0 0 0 a
2 ) a t on fi 1 |
a A) Vs ! 1 0 1 |
Table 5. Truth table to prove the associative 5 0 Fn) ee 1 1 i 1 }
law of the OR operator
A i wx | € A+(B+O) | (A+B)+€
0 0 0 0 0 2. A+(B+C)=(4+B)*
(A+)
0 0 1 t i (A+B) (A+C)
0 1 0 1 1 4d-A+A°BtA>C+B-C (Opening
0 ! 1 1 ! the brackets and multiplying)
1 0 0 1 1 =A+A°B+A’C+B>C(Since A» A=A)
1 o 1 1 1 4-(1+B)+A*C+B-C(TakeA
1 ! 0 1 1
common from the first two terms)
4+A°C+B-+C(Since 1+B=1 and
1 I 1 1 !
4-1 =A)
A(1+Cy+B-C
= A+B+C=LHS (Since 1 + C = 1 and
2. As (B+ C)=(A*BY C A-1l=A)
The truth table of the Boolean functions, shown in Let us prove this law using the truth table of the Boolean
Table 5.6, proves this law functions (Table 5.8)
80 Computer Fundamentals and Programming in C

=A BU +C)+A CL +B)
1S: Truth table to prove the second distributive law A+ B+A'C=RHS (Since 1+C=1

Ale lc|p-c |A+B-C \A+B A+ | A+B) A+ and 1+B=1)


ER KO 9, Sit nd On x 2. (A+ BYA' + C(B+ O = (4+ BYA' +O
joo1 0 ° 0 1 C) LHS (A + BYA' + CYB+ OC)
jo1o 06 0 i o ° (A: A'+A'B+A CHB CKB+C)
Jie CARE AS (eg 1 1 1 1 (Opening the brackets)
100 0 1 1 1 1 (a B+aA is +B CYB+C)
1o1 0 1 ' 1 1 aes eae B C+A'; BCH;
AB B+A°B+C+B
110 0 ' ' ' ' 4°C°C+B+C+C (Opening
the brackets)
i fs Sif 1 i 1 1 d'B+A°BC+B°C+A BC
+A C+B°C (SinceA A= A)
A's B+ Be CA+A)+B° CHAS
5.4.8 Absorption Law (Since
A+4=A)
The absorption
law permits
thereduction ofa complicated A’ B+B-C+A'C (Since A+ A’= 1)
expressic
expression intojo aa simpler
simpler one
one by absorbing
by absorbing like term:
terms. RHS (A
AA+ BYA'
+hed
C) CEO C
1, A+A*B=A d's B+A-C+B°C (SinceA: A'=0)
LHS A+AB
4-14+4°B Therefore,
LHS =RHS.
A(1 +B) (Since A» l= A)
A-1 (Since 1+B= 1) 5.4.10 De Morgan’s Laws
san The two laws of De Morgan are as follows:
2. A (A+B)=A Peis
LHS 4 (A+B) 1, (A+ By =A'-B
1 A+AB The first law states that the complement of the union
4+A-B (Since A: A= A) of two terms is the intersection of their complements.
a(1+B) (SinceA-1=A Let us prove
thislawusing the truth table of the Boolean
) 1+eeB= 1)
A 1 (Since ) functions (Table 5.9)
A RHS (Since A+ 1 = A) LEGER, Truth table to prove the first De Morgan’s law
3 "B=A+B A] 8 | AoB | Ase | at] oe | Ale
A+A'°B
(4 +A): (A+B) (Apply distributive oe RON =e . hem Ee .
law in which A+ B> C= (A+B) (A+©) Boll ' o ves ew) ba
=1:(A+B) (Since A+A'@ 1) 1 0 ' Oo) od SY 0
A+B~RHS ii \ 0 oo oy
4. As (A'+B)=A°B re
LHS A:(4'+B) ch Nae
A-A'+A°B De Morgan's second law states that the complement
=0+A*B (SinceA+ A’=0) of the intersection of two terms is the union of their
A~Be=RHS (Since A +0 A) complements.
Letus prove this law using
5.4.9 Consensus Law :
functions (Table 5.10)
: the truth tableofthe Boolean

The consensus law is the conjunction of all the unique


literals of the terms, excluding the literal that is not negated
LL LEB UD Truth table to prove the second De
Morgan’s
law
1 A+ B+A'sC+B°C=A' B+ AC A B A-B | (A-B) A B’ | A'+R’
LHS =A B+A' C+BC °o Oo 0 1 1 1 1
=A: B+A'sC+B:C:1 (Since A’ 1)=A) 0 1 0 1 1 0 1
A+ B+A'-C+B°C(A+A')
=A*B+A'-C+A*>B°C+A'-B-C i & 8 2 a : 3
As B+A-BsC+A'C+A'
BOC Le u e JEL 4
Boolean Algebra and Logic Gates 81

GGGB REPRESENTATIONS OF BOOLEAN Truth table of XOR operation


FUNCTIONS 4 B 4XORB | Minterm
r) 0 0 z
As shown in Figure 5.8, a Boolean function can be 0 i 1 m, =A'B
represented using any one of the following methods:
1 ° 1 my = AB
* A Boolean expression (canonical form) 1 1 0 J =
* Atruth table
* A logic diagram (refer to Section 5.7) By looking at the truth table, we can say that the XOR
function can be represented as a sum of the minterms or
the canonical SOP form as follows:
Representation of a Boolean function
FIA, B) = A’B + AB’
The shorthand notation is as follows:
(Boolean expression ) (Truth table) (Logic diagram )
Figure 5.8 Different ways of representing a
FIA, B) m, + my or F(A,B)=Em(1,2)
Boolean function A Boolean function with n variables has 2” minterms, as
each variable can be in cither the complemented or un-
complemented form. Thus, a three-variable function,
In Boolean algebra, a variable or a complemented F(A, B, C), bas 2° ~8 minterms as shown in Table 5.12
variable is called a literal. Designers of logical circuits
prefer to use a standardized form of literals known as
the canonical form to represent a Boolean function. ITable5.12]Minterms of a three-variable function
The key advantage of using a canonical form is that B |Minterm
it helps to reduce the number of logic gates and thus my = ABC |
interconnections between the components, thereby
im, ABC |
helping in the simplification and minimization of
digital circuits. A canonical form can be either a sum of my = ABC |
minterms or & product of maxterms m, = ABC
my = ABC” |
5.5.1 Minterm ms = AB'C |
A minterm is a canonical product (or a canonical sum of ng = ABC’
products—-SOP) term and has the following features —-—---sosooe
—--sce-os my = ABC
-eo-s=—-cs-so%7
* It includes all variables of a function.
* Each variable is in cither the un-complemented or Only those minterms for which the function produces |
complemented (inversed) form. as the output are used to represent the Boolean functions
* Each variable appears exactly once
A Boolean function can be represented as a sum of
minterms; f = I(minterms).
Aminterm |s a product term, but a product term may or
Note that the sum of minterms form is unique for any
may not be a minterm.
function. We can convert any SOP expression into the
canonical SOP form using the following steps:
* Determine the product terms of the expression.
Let us look at some examples of product terms and * Ensure that each product term has all the variables used
minterms for a function of three variables 4, B, and C in the Boolean expression.
Product terms 4, 8 AC, Ae B CAV SiC, * Ifthere is a product term in which one or more variables
A’: B are missing, then multiply that term with the sum of the
Minterms 4-8 -C.4° BC, rhe CA
missing variables and their complement.
+ Expand the Boolean expression and delete the repeated
A minterm is represented by a symbol m,, where the terms from the expression.
subscript /is the decimal equivalent of the minterm. For
example, consider the truth table of the XOR operation Example
5.1
given in Table 5.11 and note the corresponding
minterms Convert F(A, B, C) = AB’ + BC’ + AC’ to the canonical SOP form.
q Computer Fundamentals and Programming in C

ie
is, m/ = M,. It is possible tocheck this, (A’ « BY ' = 4+ B.
Multiply each term with the sum of the missing variable and Therefore, in a maxterm, 0 will be represented in the
its complement. Therefore, un-complemented form and I will be represented in the
FIA, B, C)= AB’ (C+ C’) + BC (A+A')+ AC (8 +8") complemented form.
= AB'C
+ AB'C + ABC + A'BC + ABC + ABC
By looking at the truth table, we can say that the XOR
= AB'C + AB'C’ + ABC’ + A’BC’ (Because A+A=A)
function can be represented as the product of the maxterms
or the canonical POS form as follows:
= 101+ 100+110+010
=me+my+m,_+myz F(A, B)= (A +B)» (A' +B’)
Therefore, the canonical SOP form of the given Boolean expres-
The shorthand
notation is as follows:
sion can be given asfollows:
F(A, B, C)= ms + mg + me + mz oFFIA, B, C)= Em(2, 4, 5, 6) FIA, B) = Mo-My or F(A, B) = TIM(0, 3)

re Therefore, A’ B + A» BY and (A + B) + (A' + B’) are


equivalent expressions for the XOR function.
5.5.2 Maxterm
A maxterm is a canonical sum (or a canonical product of
sums—POS) term and has the following features:
* It includes all variables of a function.
* Each variable is in cither the un-complemented or We can convert any POS expression into the canonical
complemented (inversed) form. POS form using the following steps:
* Each variable appears exactly once. * Determine the sum terms of the expression.
+ A function with n variables has 2" maxterms. * Ensure that each sum term has all the variables used in
* Each maxterm is false for exactly one combination of the Boolean expression.
input variables, * If there is a sum term in which one or more variables
are missing, then add that term with the product of the
missing variables and their complement.
+ Expand the Boolean expression and delete the repeated
terms from the expression.

Example 5.2
Let us consider some examples of sum terms and maxterms
for a function of three variables A, B, and C: Convert F(A, B, C)= (A+ B')(8 + C’) tothe canonical POS form.
Sum terms 4,4 + 8, B+ C,A' +B, A’ + BY Solution
Maxterms 4+B+C.A+B'+C,
A+ B+ CA +B +O Add each term with the product of the missing variable and
its complement. Therefore,
A maxterm is represented by a symbol M,, where the
subscript / is the decimal equivalent of the maxterm. For FIA, B, C)= [(A+ B')+ (C- CYB + C) +(A A’)
example, consider the truth table of the XOR operation S(AtB'+C-CYB+C
+A A)
given in Table 5.13 and note the corresponding maxterms. Using the distributive
law, we can write
FIA, B, C)= (A+B + CiA+ B+ CVB+C + Al(B+C +A’)
Truthtable ofXORoperation =(A+ B+ CYA+B'+C}A+B+C)(A'+B+C)
= (010)(011)(001){101)
= (Mz(M3)(M,)(Ms)
Therefore, the canonical SOP form of the given Boolean
expression can be given as
FA, B, C)=M,-M,°M, + M, orF(A,8, C)=NM(1, 2, 3, 5)

LOGIC GATES
Only those input combinations for which the function
produces 0 as the output are considered tofind the product We have seen that computers work on binary digits, which
of maxterms. form the heart of digital electronics. In digital electronics,
It should be noted that for My we have written My = We are not concemed about electrical signals; rather,
A+ B and not A’ + B'. This is because any minterm m, we just need to understand the difference between two
is the complement of the corresponding maxterm M,, that States: on (1) and off (0). Moreover, in digital electronics,
Boolean Algebra and Logic Gates 83

operations are performed using logic gates, which are also gate accepts two inputs and retums 0 if both the inputs areTy
known us Boolean gates. These gates work only on the else retums 1. The truth table of the NAND gate is given in
logic that comprises cither a 0 or 1. There are different Table 5.17, The expression involving a NAND operation can
types of Boolean gate ch of which follows a different be written as Input, |Input), or Input, Input)
set of rules. In this section, we will discuss Boolean gates
and sce how Boolean expressions can be represented using Lo eee® Truth table of NAND gate
these gates in digital electronics.
Input, Input, Output
AND gate The AND gate is represented with the> symbol 0 0 1
This gate accepts two inputs and gives an output. The output
will be | if and only if both the inputs are 1, and will be a 0 0 1 1
otherwise. The truth table of the AND gate is given in Table i 0 1
5.14. The expression involving an AND operation can be 1 1 0)
written as Input) © Input, or Input, «Input,
NOR gate The NOR gate is represented using the 2
LELICEB GR Truth table of AND gate symbol. In addition, it is known as the negated OR“or
Input, Input; Output NO OR gate. It is just the opposite of the OR gate, The
0 0 0 NOR gate accepts two inputs and returns | only if both the
inputs are low (0). The truth table of the NOR gate is given
0 1 0 in Table $,18. The expression involving a NOR operation
1 o 0 can be written as Input;—Inputy, or Input; + Input,
1 1 1
Le Eee Truth table of NOR gate
OR gate The OR gate is represented with the } > symbol Input, Input; Output
This gate accepts two inputs and gives an output. The
output will be | if any of the two inputs is 1. That is, 0 ) 1 |
it gives a 0 output only when both the inputs are 0. 0 1 0 |
The truth table of the OR gate is given Table 5.15. The 1 0 0
expression involving an OR operation can be written as 1 1 0 }
Input, \ Input, or Input, + Input).
XOR gate The XOR gate is represented using the —))-
Cee ee Truth table of OR gate symbol. The X in the XOR gate stands for exclusive, This
Input, | Input; Output means that the output from this gate will be | if only one
| 0 0 0 of the inputs is a 1, but not both. Notice in Table 5.19 that
| 0 1 i the output is a 0 if both the inputs are | or 0. In general, the
output of the XOR gate is | when the number of its high
} 1 0 1 inputs is odd. The expression involving an XOR operation
\ I 1 1 can be written as Input; ® Input. This also means that the
output will be 1 if the inputs are different
NOT gate The NOT gate is represented by the -}e- symbol
Unlike the AND and OR gates, the NOT gate accepts just one if eece Truth table of XOR gate
input, The output produced by a NOT gate is just the opposite
of the input given, For example, if the input is | the output is Input, Input, T Output
0, and vice versa. The expression involving a NOT operation 0 0 0
ean be written as NOT Input, or as ~Input, or as Input’ 0 1 1
Table 5.16 shows the truth table of this gate 1 0 I
1 1 °
Truth table of NOT gate
Input Output XNOR gate The XNOR gate is represented using the ~)>
| 0 i symbol. In addition, it is known as the negated XOR or NO
\ 1 r XOR gate and is just the opposite of the XOR gate. The
XNOR gate accepts two inputs and returns | only if both the
NAND gate The NAND gate is represented using the | > inputs are same and a 0 otherwise. The expression involving
symbol. In addition, it is known as the negated AND or NO an XNOR operation can be written as Input, ® Inputy .The
AND gate. It is just the opposite
of the AND gate. The NAND truth table of the XNOR gate is given in Table 5.20.
84 Computer Fundamentals and Programming in C

Truth table of XNOR gate


Input, | Input, Output Cc c

) 0 1 (a) AND operation

pe
(b) OR operation of the first parentheses
0 1 0 ]
' o 0 |
\ It t 1 }
(c) NOT operation

i)
LOGIC DIAGRAMS AND BOOLEAN
EXPRESSIONS
(d) OR operation of the second parentheses
A logic diagram is a pictorial representation of a
combination of logic gatestospecify a Boolean expression.
Therefore, we can directly obtain the Boolean expression
by analysing the circuit diagram or vice versa.
Let us first convert a logic circuit diagram to a Boolean
expression. In order to do this, first list the inputs at the
correct place and then process the inputs through the gates
by considering one gate at a time. Write the output of cach
gate, This will give you the resulting Boolean expression (¢) OR operation of the two parentheses
of cach of the gates. For example, consider the logic circuit
diagram given in Figure 5.9. Let us use this diagram to
obtain its cor-responding Boolean expression.
apt A")
A UJ (A' By +
c

(B+)
(f) Redrawn figure with single inputs of each input variahle
dD
wo (Be C+D EY Figure 5.10 Conversion of Boolean expression into logic
& diagram

Figure 5.9 Conversion of logic circuit diagram to Boolean Example 5.3


expression
Represent ¥ = A + B using logic gates.
Converting a Boolean expression into its equivalent logic
diagram isalittle difficult, as itrequires a good understanding Solution
of the order of operations, which is as follows: Y=A+B
* Parentheses
* NOT
* AND
* OR
Example 5.4
Now, let us draw the circuit diagram for the Boolean expression
Y=(A4+B+ C)+(B + ©)(Figure 5.10), First, consider the Represent Y= A- B using logic gates.
parentheses (4 + B +C), Within this parentheses, we will first
Solution
perform the AND operation followed by the OR operation. y
Now, consider the second parentheses (B" + C ), Within
this parentheses, we will first perform the NOT operation
followed by the OR operation
lly, the OR operation between the two parentheses
is performed in Fig-ure 5.10(c). Note that in Figure 5.10(f),
the same figure has been redrawn with single inputs of
each input variable
Boolean Algebra and Logic Gates 85

Example 5.5 5.8.1 NAND Universal Gate


Represent Y = (A~B)+ Cusing logic gates. Let us first see how the basic gates can be represented
Solution using a NAND gate
Y=tA B+ NOT Gate
A AB ANOT gate is made by joining the inputs of aNAND gate
B oY=(A- B+

pp «Dp
(Figure 5.11).
c

Example 5.6
Figure 5.11 Representation of a NOT gate
Represent Y = (A + 8) -C using logic gates.
using a NAND gate
Solution
Ye(A+B)c
AND Gate

A (A+B) An AND gate can be implemented by following a NAND


gate with a NOT gate to get a NOT NAND, that is, AND
B Y=tA+B€
output (Figure 5.12).
A A
Example 5.7 R R

Represent Y = (A 8) + (C- D) using logic gates. Figure 5.12 Representation of an AND gate
using a NAND gate
Solution
Y=(A- B)+(C- D) OR Gate
aos AB An OR gate can be implemented using a NAND gate as
shown in Figure 5.13

>>>
Y=(A-B)+(C-D)

cD

Example 5.8
Figure 5.13 Representation of an OR
Represent Y= (A+B) + C- D+ (E> F) using logic gates. gate using a NAND gate
Solution
Conversion of Boolean Expression into Circuit
Y=(A+B)+C- D+E-F)
Diagram using NAND Gates
The following are the steps to convert a given expression
into a circuit dia-gram using only NAND gates:
* Read the expression carefully and draw its corresponding
circuit diagram
* Replace every AND, OR, and NOT gate with its
equivalent NAND gate.
* Redraw the circuit.
Identify and remove double inversions (i.c¢., back-to-
back inverters, if any).
* Redraw the final circuit
GED universat Gates
Example 5.9
Universal gates are those gates that can be used for
implementing any gate such as AND, OR, and NOT. The two Y¥=A+(8-C) has been represented using AND and OR gates
important universal gates are the NAND and NOR gates. Represent it using NAND gates.
86 Computer Fundamentals and Programming in C

Y=A+(s-C) means that an AND gate can be implemented by inverting


A —_ = the inputs to a NOR gate (Figure 5.16).
B YeA+s oe

c ae

Solution

Figure 5.16 Representation of an AND gate


using a NOR gate

Conversion of Boolean Expression into Circuit


Diagram using NOR Gates
The following are the steps to convert a given expression
into a circuit diagram using only NOR gates:
* Read the expression carefully and draw its corresponding
circuit diagram.
* Replace every AND, OR, and NOT gate with its
equivalent NOR gate.
5.8.2 NOR Universal Gate * Redraw the circuit
Let us see now how the basic gates can be represented Identify and remove double inversions (i.¢., back-to-back
using a NOR gate inverters, if any).
* Redraw the final circuit
NOT Gate
The NOT gate is implemented by joining the inputs of a Example 5.10
NOR gate. This is because a NOR gate is equivalent to an
OR gate leading to a NOT gate (Figure 5.14). Y=(A-B) + Chas been represented using AND, OR, and NOT
gates. Represent it using the NOR universal gate.

pp “D-
Yru Mec

A Ree (A Ry+e
Figure 5.14 Representation of a NOT
ee
gate using a NOR gate

OR Gate
The OR gate is a NOR gate followed by a NOT gate
(Figure 5.15)

>
B a >.
Figure 5.15 Representation of an OR
gate using a NOR gate

AND Gate
From the truth tables, we can observe that an AND gate
gives the output as 1 when both inputs are 1, whereas a
NOR gate outputs | only when both inputs are 0. This
Boolean Algebra and Logic Gates 87

GE) simpiFicaTion OF BOOLEAN Locke) Truth table and K-map for four variables
EXPRESSIONS USING KARNAUGH MAP A |B) C | D | Outpuy
# c@: 0) 16 0
Karnaugh map (K-map) is a tool to represent Boolean
functions of up to six variables. It is a pictorial method ooo1 1
to minimize Boolean expressions without using oo1o 0
Boolean algebra theorems and equations, thereby CK Ope we 0
making the process of minimization simpler, faster, o 1 o 0 0
and efficient
An n-variable K-map has 2n cells where cach cell
Omms !
corresponds to an n-variable truth table value. The cells 6) find HY 1 0
in a K-map are arranged in such a way that adjacent cells ol el tae o
correspond to truth rows that differ in position by only one 100 0 0
bit (logical adjacency). i) oy io 1
K-maps can be casily used to represent expressions
€]) (Oi EG Ke 0
that involve two to four variables, expressions with
five to six variables are comparatively difficult but
3 Ga Ha 0
achievable, but expressions with seven or more 45 [el FO FS 0
variables are extremely difficult (if not impossible) to 7 Del tol 1
minimize using a K-map. gt aber OB )
Consider the truth table of two variables and observe 7 el 0
the K-map for this truth table (Table 5.21). A cell of the
K-map contains a | if the output value for 4 and B in the
truth table has a 1 Rules for Minimization
Let us consider the truth tables of three (Table 5.22) and The following are the rules for minimizing an expression
four (Table 5.23) variables and observe the K-map for
using a K-map
these tables,
Rule | Form groups of cells in such a way that a group
should not include a cell with a zero value.

Locks Truth table and K-map for two variables


A B | Output ¥
\B
o 0 1 A o 1
Oi [ht 1 0 ria.]
1) 0 I olo}
i) ig 0
Wrong: This is not a group

ceeey Truth table and K-map for three variables Rule {1 Groups may be formed either horizontally or
vertically, They cannot be formed diagonally
A|BIC Output ¥
}o 0 0 1 B
}o o 4 : \ pt
a pesos:
a oe |
|o ao S ~~ e oo
1 0; 0
(esd IEA 9 0 1T1]lo]o
ectehk Sie Se : cane |
eae :
(ca
i|
generally
2"cells. 00" 01 ll 10

Example 5.11

Considerthe expression Y = A’: B'+A- B'+A'- B. Plota


K-mapto minimize the expression.

oo Ol tt 10

In group |,there is an entry 1 when A = 0 and B=0 and when


A=Oand B = 1, which means that the output is 1 whenA=0
or A’ = 1. That is, the output is independent of the input
value
of B.
Similarly, in group li, there is a 1 when A= 0 and B =O and
when A= Land 8 = 0, which means that the output is 1when
it 10 8 = 0 or 8 = 1. Thus, the output is independent of the input
value of A. Hence, the minimized form of this expression can
be given as A’+ BY.
Therefore, Y =A’ + B’.

Cae
pated minnie
Example 5.12

Rule VI Groups can be = around the table. For Consider the expression Y= A’: B'-C' +A’: B'.C
example, the leftmost cell in a row can be grouped with +A’. B+ C+A’-B-C and minimize it using aK-map,
the rightmost cell. Similarly, the topmost cell in the table
may be grouped with the bottommost cell in the group.
in the group of 1s, we
see that the output is
independent of the values
of B and C. This is because
there is a 1 when B = 0
as well as when B = 1.
Similarly,
there is a1 when
C =0 as well as when C = 1. However, the output is 1 only
when A =0 or A’ = 1. Therefore,
Y= A’.
Leftmost cell

Example 5.13
Rule Vil The number of groups should be as small as
possible (provided any of the earlier-stated rules are not Consider the expression Y=A’»B'-C+A'-B-C+A+B'-C+
violated). A-8> Cand minimize itusing aK-map.
Boolean Algebra and Logic Gates 89

Solution In group Il, the output is independent of 8. Rather


aC The group of is is the output is 1 when A = 1 and C = 1. Therefore, group It
00 01 11 10 independent of the value minimizes to AC.
1 0 of A (as output is 1 when A In group lil, the output is independent of B. The output is
= 0 or A= 1). Similarly, the a lwhen A=0(A= 1) and C=0 whenC herefore, group
1 o}1]1jo0 output is also independent Ill minimizes to AC. Hence, Y= B+ AC +
of the value of 8. However,
the output is 1 when the value of Cis 1. Hence, the result is Example 5.15
Y=C.
Consider the expression Y = ABCD + ABCD + ABCD + ABCD +
ABCD + ABCD + ABCD + ABCD and minimize it using K-map
Solution
Example 5.14

Consider
the expression Y=A'-B'-C'+A'-B+A-8-C'+A-C
and minimize it using K-map.
Solution
A B's
C +A B+ A+B: C +A>Ccan be expanded
as,
ABU C4+A'B(CHC)4A-B-C+A-C (B48)
AB CHA BS C+A B CHA B CHA CBAC 8.
Hence, the K-map can be drawn as
[[Group wt |
Group Il

In group I, the output Is independent of A and D, The output


{ Group | ] is 1 when both B and C are equal to 1, Hence, group |
minimizes to BC.
in group Ii, the output is independent of 8 and C. The
output is 1 when A = 1 and D = 1. Hence, group II minimizes
| Group il to AD.
In group Ill, the output is independent of C. The output
In group |, the output is independent of C and A as whether is 1, when A = 0, 8 = 1, and D = 1. Therefore, group Ill
the value ofA or Cis 0 or 1 the output is always 1. So, the first minimizes to ABD.
group minimizes to B. Hence, Y= BC + AD +ABD

POINTS TO REMEMBER
© Computers understand only binary numbers, in which to represent a Boolean function. This helps them to
only the digits0and 1 are used. A complex proposition reduce the number of logic gates for simplification
can be easily stated in terms of binary variables (two and minimization of digital circuits. A canonical form
variables) and binary operators (OR, AND, and NOT). can be either a sum of minterms or a product of
Boolean operators take certain inputs and produce an maxterms.
output based on a predetermined table of results . A logic gate or Boolean gate is an electronic circuit,
{also known as the truth table). A truth table lists all which acts as a basic building block of any digital
possible values of input combinations of the function system.
and the output that will be produced based on these . NAND and NOR gates are known as universal gates
input combinations, because they can be used to implement all other logic
A Venn diagram can be used to represent Boolean gates.
operations using shaded overlapping regions. Karnaugh map (K-map) is a tool to represent Boolean
¢ A variable or a complemented variable is called a functions of upto six variables. A n-variable K-map has
literal. Designers of logical circuits prefer to use a 2" cells where each cell corresponds to an n-variable
standardized form of literals called the canonical form truth table value.
90 Computer Fundamentals and Programming in C

GLOSSARY
Boolean expression A combination of Boolean variables making the process of minimization simpler, faster, and
and Boolean operators. efficient.
Boolean function A function that has one or more input Maxterm A canonical sum (or a canonical product of
variables and generates an output based on these input sums) term.
values, which may be 0 or 1. Minterm A canonical product (or a canonical sum of
K-map A tool to represent Boolean functions of up to six products) term.
variables, which minimizes Boolean expressions without Truth table A table used to describe a Boolean function
using Boolean algebra theorems and equations, thereby of n input variables.

EXERCISES

Fill in the Blanks 5. The Boolean operator AND is also known as


1, Computers understand language. operator.
2. Binary computers work on __ logic (a) union (b) intersection
3. represent Boolean operations using shaded (c) disjunction (d) complement
overlapping regions
4. ______ is. a visual tool for defining the input-output State True or False
relationship of binary variables in a Boolean function 1. Binary language is a language of 15 and 2s.
A+0=Aisan example of slaw. 2. Boolean algebra was developed by Charles Boolean.
Avariable or a complemented variable is called a 3. In the Venn diagram, for NAND operation, the region
A_ _ is a canonical
sum term. common to both the circles is shaded to indicate ANAND
Bisl
enaw
in a maxterm, will be represented in the un
complemented form. A+ A> B= Ais given by the consensus law.
9. Alogic diagram is used to specify a Aminterm is a canonical product term.
10 and __ gates are known as universal in a maxterm, 1 is represented in the complemented form.
gates. NOwes
In a K-map, groups of cells are formed such that they do
not include a cell with the value 1
Multiple-choice Questions Review Questions
1, The operator that returns 1 when both the inputs are 1. What is Boolean algebra? Give its applications
false is: 2. Explain Boolean laws using Venn diagrams.
(a) AND (b) OR 3. Draw the Venn diagram for the Boolean expression
(ce) NAND (4) NOR AvBay nc.
2. A Boolean function of n variables has _ rows of 4. Explain the utility of a truth table as a visualization tool in
possible input combinations. Boolean algebra
(a) 9 (b) 2° Draw the truth table for 2=A (BU C)
(c) 2" (d) 2"-1 Prove the validity of the consensus and absorption laws.
3, A+B+C=(A+B)(A+C)isanexampleof__ law. How are Boolean functions represented?
(a) Involution (b) Commutative Differentiate between a minterm and a maxterm.
(c) Distributive (d) Absorption Cenaw
Give the minterms and maxterms for the Boolean AND
operation.
4, AK-map represents Boolean functions of up to
variables. 10. Explain the steps to convert an SOP expression into its
canonical SOP form with the help of an example.
(a) 2 (b) 4
11. Convert F(A, 8, C) = A'B + B'C + A’C to the canonical SOP
(c) 6 {d) 8 form.
Boolean Algebra and Logic Gates 91

12 Explain the steps to convert a POS expression into the Implement the expressions given in Question 16 using
canonical POS form with the help of an example. NAND gates
13, Convert F(A, B, C) = (A' + B')(8' + C) to the canonical POS Implement the expressions given in Question 16 using
form. NOR gates.
14. What are logic diagrams? How are they useful? Write a short note on K-maps
15. Draw the logic diagram for the Boolean expression Y = Draw a K-map and simplify the Boolean expression given
(A-B+C -D)+(A'+Dd) by fix, y, 2) = Zm(0, 2, 3, 4, 6, 7)
16. Implement the following expressions using logic gates
(a) Y=(A-8)+(C-D)-E
(b) Y=A4(C+D)-(A-B)
Pm 4
+ Sos >

Computer Software
a”
TAKEAWAYS
© System software © Application software * Command interpreter
* BIOS © Pre-written software * Mobile operating systems
© Operating systems © Customized software * Generations of programming
© Utility software © Productivity software languages
* Translators * Microsoft Office

Computer hardware cannot think and make decisions


83 INTRODUCTION To ComPUTER on its own. Hence, it cannot be used to analyse 4 given set
SOFTWARE of data and find a solution on its own. The hardware needs
a software (a set of programs) to instruct what has to be
When we talk about a computer, we actually mean the done. A program is a set of instructions that is arranged
following two parts. in a sequence to guide a computer to find a solution for a
* The first is the computer hardware, which performs all given problem. The process of writing a program is called
the computation and calculation work that computers programming.
are known for. Computer software is written by programmers using
* The second part is the computer software, which 4 programming language. The programmer writes a set
instructs the hardware what to do and how to do it of instructions (program) using a specific programming
language. Such programs are known as the source code.
Figure 6.1 illustrates these parts Another computer program called a compiler is then used
If we think of a computer as a living being, then the on the source code, to transform the instructions into a
hardware would be the body that performs actions such as language that the computer can understand. The result is
secing with the eyes, lifting objects, and filling the lungs an executable computer program, which is another name
with air, The software would be the intelligence that helps for software.
in interpreting the images that are seen through the eyes, Examples of computer software include the following
instructing the arms how to lift objects, and instructing the
body to fill the lungs with air * Driver software, which allows a computer to interact
Since the computer hardware is a digital machine, it can with hardware devices such as printers, scanners, and
understand only two basic values—on and off. The on and video cards.
off concept forms the basis of binary language. Computer Educational software, which includes programs and
software was developed to convert binary language into a games that help in teaching and providing drills to help
form that is useful to tell the computer hardware what to do. memorize facts, Educational software can be used in

Computer system

Computer hardware Computer software

System software Application software

Figure 6.1 Parts of a computer system


Computer Software 93

diverse areas, from teaching computer-related activities


like typing to subjects like chemistry.
Media players and media development software, which
are specifically designed to play and/or edit digital
media files such as music and videos.
For example, games, spreadsheets, word
Productivity software, which is an older term used to
processor, database systems. web browsers
denote any program that allows the user to be more
productive in a business sense. Examples of such
software include word processors, database management
utilities, and presentation software.
Operating systems software, which helps in coordinating For example, operating system
system resources and allows execution of other
programs. Some cxamples of operating systems arc
Windows, Mac OS X, and Linux
Computer hardware
Computer games, which are widely used as a form of For example, printer, mouse, scanner, keyboard,
entertainment software that has many genres. CPU, hard disk

ED cuassiFication oF ComPUTER Figure 6.2 Relationship among hardware, system


SOFTWARE software, and application software

Computer software can be broadly classified into two Differences between system and application
groups, namely application software and system software. software
* Application software is designed for users to solve a System software ] Application software
particular problem. It is generally what we think of when
Itis a collectionof programs —Itisa collection of programs:
we refer to a computer program. Examples of application that cnable users tointeract —_written fora specific application,
software include spreadsheets, database systems, desktop with hardware components — such as a library system,
publishing software, program development software, efficiently. inventory control system, and
games, and web browsers. Simply put, application © 08,
sofiware represents programs that allow users to do
Ktcontrols
and manages the —_It uses the services provided by
something besides merely run the hardware. hardware. the system software to interact
* On the contrary, system sofiware, provides a general with hardware components,
programming environment in which programmers can
Tt is machine-dependent. Itis machine independent,
create specific applications to suit their needs, This
The programmer must Tn most cases, the programmer
environment provides new functions that are not available
understand
the architecture ignores the architecture
ofthe
at the hardware level and performs tasks related to executing of themachine and hardware —machine and hardware details to
the application program. System software represents details to write system write application software,
programs that allow the hardware to run properly. It acts as software.
an interface between the hardware of the computer and the
Itinteractswith the hardware It interacts with the hardware
application software that users need to run on the computer. directly, indirectly through system calls
Figure 6.2 illustrates the relationship between application provided by system software.
sofiware and system software,
Writing
system software isa = Writing application programs ix
Table 6.1 lists the differences between system and complicated task. relatively easy.
application softwares. Examples include compilers Examples include Microsoft
inn Ans ee eee ee
6.2.1 System Software
S stem software is computer software designed to operate BIOS is built into the computer and is the first code run
computer hardware and to provide and maintain a platform by the computer when it is switched on. The key role of
for running application software. Some of the most widely BIOS is to load and start the operating system (OS).
used system software are discussed in this section. When the computer starts, the first function that BIOS
performs is to initialize and identify system devices such
Computer BIOS and Device Drivers as the video display card, keyboard, mouse, hard disk,
CD/DVD drive, and other hardware. In other words, the
Basic Input/Output System (BIOS) and device drivers code in the BIOS chip runs a series of tests called POST,
provide basic functionality to operate and control the which stands for power on self test, to ensure that the
hardware connected to or built into the computer. system devices are working correctly
94 Computer Fundamentals and Programming in C

Similarly. if we examine the programs that help us in