Module 1 - Comp 312 - Computer Fundamentals and Programming
Module 1 - Comp 312 - Computer Fundamentals and Programming
Module
COMPUTER FUNDAMENTALS AND
1 PROGRAMMING
OVERVIEW:
Think about some of the different ways that people use computers. In school,
students use computers for tasks such as writing papers, searching for articles, sending
email, and participating in online class. At work, people use computers to analyze data,
make presentations, conduct business transactions, communicate with customers and co-
workers, control machines in manufacturing facilities, and do many other things. At home,
people use computers for tasks such as paying bills, shopping online, communicating with
friends, and playing computer games. And don’t forget cellphones, car navigation systems,
and many other devices are computers too. The uses of computers are almost limitless in
our everyday lives.
Computers can do such a wide variety of things because they can be programmed.
This means that computers are not designed to do just one job, but to do any that their
programs tell them to do.
This chapter discusses the computer organization; number system and data
representation: number system operations, radix conversion, representation of negative
integers, non-numeric value representation and binary data access and representation.
Below is a list of knowledge that maybe you have encountered in your previous
computer subjects. Check the appropriate box corresponding to your agreement to
the statement using the scale given below.
Statements 5 4 3 2 1
I can identify the basic parts of a computer system
AUTOMATIC
Speed
A computer is a very fast device. It can perform in a few seconds, the amount of
work that a human being can do in an entire year, if he/she worked day and night and did
nothing else. In other words, a computer can do in a few minutes what would take a man his
entire lifetime.
While talking about the speed of a computer we do not talk in terms of seconds or
even milliseconds (10-3) but in terms of microseconds (10-6), nanoseconds (10-9), and even
picoseconds (10-12). A powerful computer is capable of performing several billion (109)
simple arithmetic operations per second.
Accuracy
In addition to being very fast, computers are very accurate. Accuracy of a computer
is consistently high and the degree of its accuracy depends upon its design. A computer
performs even calculation with the same accuracy.
However, errors can occur in a computer. These errors are mainly due to human
rather than technological weaknesses. For example, errors are mainly due to human rather
than technological weaknesses. For example errors may occur due to imprecise thinking by
a programmer (a person who writes instructions for a computer to solve a particular
problem) or incorrect input data. We often refer to computer errors caused due to incorrect
input data or unreliable programs as garbage-in-garbage-out (GIGO).
Unlike human beings, a computer is free from monotony, tiredness, and lack of
concentration. It can continuously work for hours without creating any error without
grumbling. Hence, computers score over human beings in doing routine type of jobs that
require great accuracy. If ten millions calculations have to be performed, a computer will
perform that last one with exactly the same accuracy and speed as the first one.
Versatility
Versatility is one of the most wonderful things about a computer. One moment it is
preparing results of an examination, next moment it is busy preparing electricity bills, and in
between. It may be helping an office secretary to trace an important letter in seconds. All
that is required to change its talent is to slip in a new program (a sequence of instructions
for the computer) into it. In brief, a computer is capable of performing almost any task, if
the task can be reduced to a finite series of logical steps.
Power of Remembering
No IQ
A computer is not a magical device. It possesses no intelligence of its own. Its I.Q. is
zero at least until today. It has to be told what to do and in what sequence. Hence, only
users determine what tasks a computer will perform. A computer cannot take its own
decision in this regard.
No Feelings
Computers are devoid or emotions. They have no feelings and no instincts because
they are machines. Although men have succeeded in building a memory for computer, but
no computer possesses the equivalent of a human heart and soul. Based on our feelings,
taste, knowledge, and experience we often make certain judgments in our day-to-day life
whereas, computers cannot make such judgments on their own. They make judgments
based on the instructions given to them in the form of programs that are written by us
(human beings).
No Self Intelligence
Today, a computer is able to do a work which is impossible for man. Computers are
used to do risky and dangerous work and where sharp actually is needed. But it does not
have any intelligence of its own. It works according to the instruction only.
No Decision-Making power
Computer cannot take any decision of its own. It does only those tasks which are
already instructed to it.
No learning power
Computer has no learning power. Once you give instructions to a computer how to
perform a task, the very task is cannot perform if you do not give it any instructions for the
next time. For example, when you are taught how to solve a problem and if same type of
problem is given you to solve, then you can do it.
Emotionless
Computers are emotionless. They do not have emotion, like dislike feelings. They are
simply machines which work as per the instruction given to them.
Although computers are great help to human beings, it is commonly felt that we
people have become so dependent on calculator that we cannot make very simple
calculation without calculator. Sometimes, find it difficult to instantly speak out even that
telephone number which they use every now and then as they have got the habit of using
them by retrieving the storage.
Thanks to computer and the Internet, the world has gotten much smaller in recent
years. Many people use their computers to keep in touch with friends and family using
instant messenger programs as well as email. A growing communication tool is social
networking, with sites like Face book and Twitter becoming incredibly popular.
Games
PCs have long served as recreational devices with hundreds of games available each
year. Gaming on a PC can be an expensive hobby, with video cards ranging in price from $60
to more than $400 and fully equipped gaming PCs costing in excess of $1500 in many cases.
For all the top-tier AAA titles, there are other games that users can find both pre-installed
on PCs as well as online.
Entertainment
Almost all computers come with CD or DVD disk drives, which allow you to use the
computer as a CD player or DVD player. Some computers are also capable, with the proper
hardware, of viewing and recording television onto the machine’s hard drives. With an
Internet connection, users have a nearly limitless of videos and music available online as
well.
Work
System Components
CPU/Microprocessor
Memory Subsystem
I/O Subsystem
System Buses
Address Bus
Data Bus
Control Bus
Instruction Cycle
Fetch
Decode
Execute
Isolate I/O
Memory-mapped I/O
CPU Organization
Types of Memory
Static RAM
Dynamic RAM
ROM
PROM
EPROM
EEPROM
based on stored
program design
processor system
CPU
memory
input/output system
input/output
devices
secondary
storage
Main Memory
(fast access) storage device for preserving binary
data and instructions
memory is divided into units or words
each is usually a standard size or fixed-length
each memory word has a unique address for
random access
memory
memory
data
address
register
register
accumulator
instruction (work
register register)
program arithmetic
counter logic unit
system
clock
instruction is transferred to
and decoded in the IR
Program Control
starting a program
halting a program
skipping to other
instructions
testing data to decide
whether to skip over
some instructions
We are very familiar with the way the decimal number system represents numeric
characters. In this system, the base is 10 and 10 possible entries are used to represent
values. However, deep into the hardware level of machines, the computer understand only
one specific format, which is the combination of 0s and 1s called the binary number system.
To understand the inner workings of machines, we need to learn the relationship among
these number systems.
This lesson will deal with how numeric data are represented and converted from one
radix to another. Negative number representation with the use of radix and reduced radix
complement are also discussed. The code representation of alpha numeric and special
characters are also dealt with.
The last topic shows the relationship of the byte, nibble, word and double word to
the binary digit (bit).
2. Binary System – uses only 2 symbols, 0 and 1, and is mostly used for computer
applications. For example, 10 in the decimal systems is equal to 2 in the decimal
system.
The different number systems (decimal, binary, octal and hexadecimal) have their
particular addition and subtraction rules. On the other hand, numbers from one radix (or
number system) can also be converted into another by using formulas. The two most
important formulas for conversion are:
From Decimal to any Radix: Multiply the number by its corresponding quotient by
the radix until the quotient becomes zero. Gather all remainders with the recent
remainder as most significant to the first remainder, which is the least significant.
1 nibble = 4 bits
1 byte = 8 bits
1 word = 2 bytes
1 double = 4 bytes
These combinations of binary digits are used in calculating space for computer
storage and memory.
Base/Radix: 10
Valid Entries: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Weighted Representation:
1234 = 1 x 103 + 2 x 102 + 3 x 101 + 4 x 100
= 1 x 1000 + 2 x 100 = 3 x 10 = 4 x 1
Add the lowest positional value column. Check the sum of the specifies column:
If the sum is still a valid entry, write the sum on the same column
position.
If the sum is not a valid entry, continuously subtract the radix until the
entry sum is valid. The carry over to the next higher positional value is
the number of times the radix was subtracted to make the entry valid.
Continue adding the next higher positional value until all the positional values are
exhausted.
Example:
result: 609
Try this . . .
Practice Exercise
Addition
Example:
result: 437
Try this . . .
Practice Exercise
Subtraction
1. 10054 – 8563
2. 8765 – 3936
3. 4467 – 3109
4. 7200 – 6753
5. 8903 - 3335
Base/Radix: 2
Valid Entries: 0, 1
Weighted Representation:
10012 = 1 x 23 + 0 x 22 + 0 x 21 + 1 x 20
=1x8+0x4+0x2+1x1=9
The following are the four basic rules in addition of binary numbers:
02 + 02 = 02 02 + 12 = 12
12 + 02 = 12 12 + 12 = 102
Example:
1 0 1 1 02 1st digit: 02 + 12 = 12
± 01011 2nd digit: 12 + 12 = 2 (not valid) – 2 (radix) = 02
1 0 0 0 0 12 3rd digit: 12 + 02 +12 (carry-over)
= 2 (not valid) – 2 (radix) = 02
4th digit: 02 + 12 + 12 (carry-over)
= 2 (not valid) – 2 (radix) = 02
5th digit: 12 + 02 + 12 (carry-over)
= 2 (not valid) -2 (radix) = 02
6th digit: 12 (carry-over)
Result: 1000012
Try this . . .
Practice Exercise
Addition of Binary Numbers
1. 101112 + 111102
2. 100112 + 111012
3. 1102 + 1112 + 1112 + 1112
4. 1101102 + 1111002 + 1110002
5. 10010012 + 11111112 + 10111112
Example:
result: 012
Try this . . .
Practice Exercise
Subtraction of Binary Numbers
1. 10012 - 112
2. 1011102 - 11012
3. 100002 - 112
4. 1010112 - 1112
5. 1110012 - 1012
Base/Radix: 8
Valid Entries: 0, 1, 2, 3, 4, 5, 6, 7
Weighted Representation:
14468 = 1 x 83 + 4 x 82 + 4 x 81 + 6 X 80 = 1
= 1 x 512 + 4 x 64 + 4 x 8 + 6 X 1 = 806
Example:
4 4 68 1st digit: 68 + 18 = 7
± 3 4 18 2nd digit: 48 + 48 = 8 (invalid) – 8 (radix) = 08 with carry 1
1 0 0 78 3rd digit: 48 + 38 + 18 (carry) = 8 (invalid) – 8 (radix) = 08
with carry 1
4th digit: 1 (carry-over)
result: 10078
Try this . . .
Practice Exercise
Addition of Octal Numbers
1. 37658 + 5254
2. 15678 + 64778
3. 4328 + 7668
4. 57308 + 7428
5. 33118 + 73458
Example:
result: 3758
Base/Radix: 16
Valid Entries: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Where A = 10, B = 11, C = 12, D = 13, E = 14, F = 15
Weighted Representation:
C1216 = 12 x 162 + 1 x 161 + 2 x 160
= 12 x 256 + 1 x 16 + 2 x 1 = 3090
Example:
result: 14CF16
Try this . . .
Practice Exercise
Addition of Hexadecimal Numbers
1. A8516 + 38916
2. CAD16 + FEE16
3. B89D16 + 362916
4. ABCD16 + CDEF16
5. AB16 + BC16 + CD16 + DE16 + EF16
Example:
8 3 716 1st digit: 716 - A16 = (cannot be so borrow from next position)
2 5 A16 = 716 + 16 (radix borrowed) – 10 (value of A16) = D16
5 D D16 2nd digit: 316 – 116 (borrowed) – 516 = (cannot be so borrow)
= 216 + 16 (radix borrowed) – 516 = D16 (equivalent of 13)
3rd digit: 816 – 116 = (borrowed) – 216 = 516
result: 5DD16
Try this . . .
Practice Exercise
Subtraction of Hexadecimal Numbers
1. C89316 – 2AB16
2. 3BBE – F2616
3. 987616 – 2ABC16
4. 1AB216 – DEC16
5. 1000016 - 934216
6.
Divide the whole number by the radix required. Get the quotient and remainder.
Repeatedly divide the quotient by the radix required until the quotient becomes
zero. Take note of all remainders.
Get all the remainders, the most recent remainder is the most significant position
(msp) and the first remainder is the least significant position (lsp).
Example:
36 = __________2
result: 1001002
Try this . . .
Practice Exercise
1. 506 = ____________16
2. 316 = ____________8
3. 95 = _____________2
4. 448 = ____________16
5. 426 = ____________8
6. 215 = ____________2
Examples:
1. 0.35810 = _____________2
Please note that sometimes, when we convert decimal fraction into binary fraction,
an infinite binary fraction is obtained.
2. 0.35810 = _____________8
Try this . . .
Practice Exercise
1. 10.52310 = _________2
2. 30.65310 = _________8
3. 445.24610 = ________16
4. 96.3510 = __________2
5. 128.3610 = _________2
6. 644.32510 = ________16
The following are the rules in the conversion of any whole number radix into
decimal.
Examples:
1. 1101112 = ____________10
1101112
1x20 = 1x1 = 1
1x21 = 1x2 = 2
1x22 = 1x4 = 4
0x23 = 1x8 = 0
1x24 = 1 x 16 = 16
1x25 = 1 x 32 = 32
55
result: 1101112 = 5510
6x80 = 6x1 = 6
7x81 = 7x8 = 56
3x82 = 3 x 64 = 192
254
3. 8 B 8 16 = _________10
8 x 16 0 = 8 x 1 = 8
11 x 16 1 = 11 x 16 = 176
8 x 16 2 = 8 x 256 = 2048
2232
Try this . . .
Practice Exercise
1. ABC16 = _________10
2. 7768 = _________10
3. 111112 = _________10
4. B0B16 = _________10
5. 4278 = _________10
6. 1011111 = _________10
The following are the rules in the conversion of any fraction radix into decimal.
Examples:
1. 0.7 2 3 8 = _________10
3 x 8 -3 = 3x1 = 0.0058593
2 x 8 -2 = 2 x 16 = 0.03125
-1
7 x 8 = 7 x 256 = 0.875
0.9121093
result: 0.7238 = 0.912109310
2. 0.1 1 0 1 2 = _________10
1 x 2 -4 = 1 x 0.0625 = 0.0625
0 x 2 -3 = 0 x 0.125 = 0.0
1 x 2 -2 = 1 x 0.25 = 0.25
1 x 2 -1 1 x 0.5 = 0.5
0.8125
3. 0.B 2 B 16 = _________10
11 x 2 -3 = 11 x 0.0002441 = 0.0026851
2 x 2 -2 = 2 x 0.0039063 = 0.0078126
11 x 2 -1 = 11 x 0.25 = 0.6875
0.6979977
result: 0.B2B16 = 0.6979977 10
Try this . . .
Practice Exercise
1. 10.3328 = __________10
2. 2A.6B16 = __________10
3. 100.10012 = ________10
4. 124.5658 = _________10
5. C95.25616 = ________10
6. 101.1012 = _________10
The following are the rules of conversion from any radix number into another radix
other than decimal.
Examples:
1. 1101112 = ____________8
A B B Equivalent AxB
1 20 1 1
1 21 2 2
1 22 4 4
0 23 8 0
1 24 16 16
1 25 32 32
Total 5510
Shortcut:
Each octal digit is equivalent to three binary digits. Group all binary digits by
three’s starting from the rightmost to the leftmost digit, then add their corresponding
weighted value.
110 1 1 12
weighted value 4 2 1 4 2 1
6 7
A B B Equivalent A*B
1 20 1 1
1 21 2 2
1 22 4 4
0 23 8 0
1 24 16 16
1 25 32 32
Total 55
16 55 Rem 7 lsp
16 3 Rem 3 msp
0
Shortcut:
Each hexadecimal value is equivalent to four binary digits. Group the binary digits
into groups of four starting from the rightmost digit towards the leftmost digit. Add their
corresponding weighted values.
0011 0 1 1 12
weighted value 0 4 2 1 8 4 2 1
3 7
3. 1238 = ____________2
First, convert 1238 into decimal and then convert the result computed into binary.
1 2 3 8 = _________10
3x80 = 3x1 = 6
2x81 = 2x8 = 16
1x82 = 1 x 64 = 64
83
8310 = ____________2
result: 10100112
Shortcut:
An octal digit is equivalent to three binary digits; hence, we have to assign three
binary digits per octal digit. The three binary digits have weighted values of 4, 2, and 1,
respectively. Place the value 1 on all weighted values needed to come up with equivalent
octal digit, otherwise, put the value zero.
1 2 3
001 010 011
weighted value 4 2 1 4 2 1 4 2 1
result = 10100112
4. BED16 = ____________2
B E D 16
A B A*B
0
D = 13 16 = 1 13
E = 14 161 = 16 224
B = 11 162 = 256 2816
TOTAL 3053
result: 1 0 1 1 1 1 1 0 1 1 0 1 2
Shortcut:
Each hexadecimal value is equivalent to four binary digits. Break each hexadecimal
digit into four binary digits each. The weighted values of the four binary digits are 8, 4, 2,
and 1, respectively. Put the value 1 to all weights needed to come up with the equivalent
value, otherwise, put the value zero.
B E D
1011 1110 1101
weighted value 8 4 2 1 8 4 2 1 8 4 2 1
result = 1011111011012
Try this . . .
Practice Exercise
1. 1011112 = _____________8
2. 11011011102 = _____________16
3. 2468 = _____________2
4. 3658 = _____________16
5. 45F16 = _____________2
6. 4CD316 = _____________8
7. 111011112 = _____________8
8. 11100111112 = _____________16
9. 35368 = _____________2
10. 45678 = _____________16
11. B2C416 = _____________2
12. F56316 = _____________8
The absolute value representation uses an eight-bit representation where the first bit
corresponds to the sign and the last seven bits to the value of the number. A value of 1 in
the first bit means negative while a zero value represents a positive value.
Example:
-15 is represented as
1 0 0 0 1 1 1 1
+15 is represented as
0 0 0 0 1 1 1 1
Limitations:
The two types of radix complements are radix complement and reduced radix complement.
affix 1 on the
th
8 bit
The character codes are usually represented as one byte or 8 bits. They can be
represented using the following:
It was established by ISO in 1967 containing a 7-bit character code based on the SCII
code. Considered the base of character codes all over the world.
The EBCDIC was the character code developed by IBM for all its IBM computers. It
became a “de facto” standard because of the large number of users using IBM.
Unicode
A number system does not change the value of the number, but only the manner in
which it is represented.
The decimal system is a positional-value system in which the value of a digit depends
on its position.
The decimal point separates the positive powers of 10 from the negative powers.
The binary system is positional-value system, wherein each binary digit has its own
value or weight expressed as a power of 2.
The hexadecimal number system is known as the base-16 number system, because
each position in the number represents an incremental number with a base of 16.
KEYWORDS
Binary System: It is a positional-value system, where in each binary digit has its own value
or weight expressed as a power of 2.
Digital Systems: Digital systems process digital signals which can take only a limited number
of values (discrete steps) usually just two values are used: the positive supply voltage (+Vs)
and zero volts (0V).
Hexadecimal Number System: It is known as the base-16 number system, because each
position in the number represents an incremental number with a base of 16.
Number System: It is a basic counting various items. On hearing the word number all of us
immediately think of the familiar decimal number system with its 10 digit: 0, 1, 2, 3, 4, 5, 6,
7, 8, and 9.
Octal: The octal, or base 8, number system is a common system used with computers.
Because of its relationship with the binary system, it is useful in programming some types of
computers.
Osergaard, Erik. (10 March 2003). Computer data representation and number
systems.
Online Available: http://www.danbbs.dk/~erikoest/binary.htm.
Albano, Gisela May A., Atole, Ronnel R., Ariola, Rose Joy Y. (2003).
Introduction to Information Technology. Philippines: Trinitas Publishing, Inc.
www.google.com
Main Task
Computer and convert the following numbers based on the radix required: