Chapter 2 3
Chapter 2 3
Chapter 2 3
2.4 Glossary
2.5 Answers to Exercise
2.1 INTRODUCTION
The binary number system and digital codes are fundamental to computers.
In this chapter, the binary number system and its relationship to other
systems such as decimal, hexadecimal, and octal are introduced. Arithmetic
operations with binary numbers are discussed to provide a basis for
understanding how computers and many other types of digital systems work.
Also binary coded decimal (BCD), and alpha numeric codes are introduced.
Binary logic gates are explained with the help of logic diagram, block
diagram and truth table.
A binary number system is a code that uses only two basic symbols. The digits
can be any two distinct characters, but it should be 0 or 1. The binary
equivalent for some decimal numbers are given below
decimal 0 1 2 3 4 5 6 7 8 9 10
binary 0 1 10 11 100 101 110 111 1000 1001 1010
Each digit in a binary number has a value or weight. The LSB has a value of 1.
The second from the right has a value of 2, the next 4 , etc., If we have a
binary number 11001, then the LSB has value 1 ,the MSB has value 16, and
the number has value 25.
16 8 4 2 1
4 3 2 1
2 2 2 2 20
1 1 0 0 1
MSB LSB
A series of eight bits makes a byte, much as 12 makes a dozen. With 8 bits
there are 28 = 256 possible combinations, so a byte can be 256 possible
values from 0 (0000 0000) to 255 (1111 1111). The unit symbol for the byte is
the upper-case character B, while the bit is represented by a lower-case
character b.
(0.4375) 10 = (0.0111) 2
2.2.2 Octal Number System
Octal number system has a base of 8 i.e., it has eight basic symbols. First eight
decimal digits 0, 1,2,3,4,5,6,7 are used in this system.
Multiply by 8 Digit
0.11 x 8 = 0.88 0
0.88 x 8 = 7.04 7
0.04 x 8 = 0.32 0
0.32 x 8 = 2.56 2
0.56 x 8 = 4.48 4
(19.11) 10 = (23.07024) 8
Octal to binary conversion :
Since the base of octal number is 8, i.e., the third power of 2, each octal
number is converted into its equivalent binary digit of length three.
(1101101.11101) 2 = (155.72) 8
Hexadecimal to binary:
Since the base of hexadecimal number is 16, i.e., the fourth power of 2, each
hexadecimal number is converted into its equivalent binary digit of length
four.
E.g.: (5D. 2A) 16 = (…….) 2
5 D . 2 A
0101 1101 . 0010 1010
( 5 D. 2 A) 16 = ( 0101 1 10 1. 0 01 0 1 0 1 0 )
Decimal to hexadecimal:
The decimal number is divided by 16 and carries are taken after each division
and then written in the reverse order. The fractional part is multiplied by 16
and carry is taken in the forward order.
(2479.859) 10 = (9AF.DBE76) 16
0101 1010
1001 0110
1101 0010
0001 1110
Thus 1’s complement of a binary number is the number that results when we
change each 0 to a 1 and each 1 to a 0.
2’s Complement: 2’s complement results when we add ‘1’ to 1’s complement
of the given number i.e., 2’s complement =1’s complement + 1
Binary Number 1’s comple me nt 2’s comple me nt
1011 x
110
0000
1011
1011 __
1000010_
E.g.:
101.01 x 11.01
101.01 x
11.01
10101
00000
10101
_10101 __
10001.0001
Binary division :
The table for binary division is as follows.
0÷1=0
1÷1=1
As in the decimal system division by zero is meaning less.
E.g:
Computers, printers and the other devices must process both alphabetic and
numeric information. Serial coding systems have been developed to represent
alphanumeric information as a series of 1’s and 0’s. The characters to be coded
are alphabets(26), numerals (10) and special characters such as +,-, /,*, $ etc,
In order to code a character, string of binary digits is used. In order to ensure
uniformity in coding, two standard codes have been used.
1. ASCII: American Standard Code for Information Interchange.
2. Unicode :
ASCII :
It is a character encoding standard for electronic communication.
American Standard Code for Information Interchange(ASCII) and was
first launched in 1963. ASCII codes are used to represent text in
computers and telecom devices.
ASCII is used for representing 128 English characters in the form of
numbers, with each letter being assigned to a specific number in the
range 0 to 127. For e.g., the ASCII code for uppercase A is 65,
uppercase B is 66, and so on. Check out the following table for some
more examples.
Most computers are using ASCII encoding for text representation, which
makes transferring data from one device to another a lot easier.
Unicode :
is a text encoding standard maintained by the Unicode Consortium
designed to support the use of text written in all of the world's major
writing systems
Unicode provides a unique way to define every character in every
spoken language of the world by assigning it a unique number. The
Unicode standard is maintained by the Unicode Consortium and
defines more than 1,40,000 characters from more than 150 modern
and historic scripts along with emoji.
Hexadecimal Subtraction
Uses the same principle of "borrowing" that decimal and binary subtraction uses.
borrow
Minuend 6E 6E
Subtrahend - 29 29
Difference 5 45
borrow 1 01 0 01
Minuend AC3 AC3 AC3
Subtrahend - 604 -6 04 -604
Difference F BF 4 B F
2.3.2 OR gate
An OR gate (Figure 2.2) produces a high output when any or the entire
inputs are high. The output is low only when all the inputs are low.
A Y=Ā
0 1
1 0
If two NOT gates are cascaded then the output will be same as the input and
the circuit is called buffer circuit.
A B Y= AB
0 0 1
0 1 1
1 0 1
1 1 0
A B Y= A B
0 0 1
0 1 0
1 0 0
1 1 0
2.3.6 XOR gate: XOR (Figure 2.6) gate is an abbreviation of exclusive OR gate.
It has two inputs and one output. For a two input XOR gate, the output is
high when the inputs are different and the output is low when the inputs are
same. In general, the output of an XOR gate is high when the number of its
high inputs is odd. The Boolean expression of the XOR gate is Y = A.B’ + A’.B
A B Y= A B
0 0 0
0 1 1
1 0 1
1 1 0
First part
There are 3 inputs; thus we must have 2^3 (i.e. 8) possible combinations of 1s
and 0s. To find the values (outputs) at points P and Q, it is necessary to consider
the truth tables for the NOR gate (output P) and the AND gate (output Q) i.e.
P = A NOR B
Q = B AND C
Which now gives us the final truth table for the logic circuit given at the
start of the example:
2.The output of gate is LOW when at least one of its inputs is HIGH. It is true
for (a) AND (b) NAND (c) OR (d) NOR
3.The output of gate is HIGH when at least one of its inputs is LOW. It is true
for (a) AND (b) OR (c) NAND (d) NOR
4.The output of a gate is HIGH if and only if all its inputs are HIGH. It is true
for (a)XOR (b) AND (c) OR (d) NAND
5. The output of a gate is LOW if and only if all its inputs are HIGH. It is true
for (a)AND (b) XNOR (c) NOR (d) NAND
9. Which of the following rules states that if one input of an AND gate is
always 1 , the output is equal to the other input ?
(a) A + 1 = 1 (b) A + A = A (c) A.A = A (d) A . 1 = A
1.(d) 2.(a) 3.(c) 4.(a) 5.(d) 6.(b) 7.(d) 8.(b) 9.(c) 10.(c)
STRUCTURE
3.0 Introduction
3.3 Altgorithms
3.4 Flowcharts
There are three types of errors that can be arised during the phases of problem
solving:
Step 2 : Define the variables: Algorithm's variables allow you to use it for more
than one place. We can define two variables for rectangle height and
rectangle width as HEIGHT and WIDTH (or H & W). We should use
meaningful variable name e.g. instead of using H & W use HEIGHT
and WIDTH as variable name.
Step 3 : Outline the algorithm's operations: Use input variable for computation
purpose, e.g. to find area of rectangle multiply the HEIGHT and
WIDTH variable and store the value in new variable (say) AREA. An
algorithm's operations can take the form of multiple steps and even
branch, depending on the value of the input variables.
Step 4 : Output the results of your algorithm's operations: In case of area of
rectangle output will be the value stored in variable AREA. if the
input variables described a rectangle with a HEIGHT of 2 and a
WIDTH of 3, the algorithm would output the value of 6.
Flow charts can be used to document virtually any type of business system, from
the movement of materials through machinery in a manufacturing operation to
the flow of applicant information through the hiring process in a human
resources department.
Each flow chart is concerned with one particular process or system. It begins with
the input of data or materials into the system and traces all the procedures
needed to convert the input into its final output form.
Specialized flow chart symbols show the processes that take place, the actions
that are performed in each step, and the relationship between various steps.
Flow charts can include different levels of detail as needed, from a highlevel
overview of an entire system to a detailed diagram of one component process
ithin a larger system. In any case, the flow chart shows the overall structure of
the process or system, traces the flow of information and work through it, and
highlights key processing and decision points.
Format : Begin
statement 1.
statement 2.
…
statement n.
End
Begin
display age
End
In the case of TRUE, one of the two branches is explored; but in the case of
FALSE condition, the other alternative is taken. Generally, the ‘IF-THEN’ is used to
represent branch control.
Format:
if (condition)
then-part
else
else-part
end_if
EX 2: Determine if a man is retired
Begin
Begin
read age
if (age > 55)
print “Retired”
else
print “Still working”
end_if
End
Sometimes in certain situation, we may omit the else-part.
if (number is equal to 1)
print “One”
else if (number is equal to 2)
print “Two”
else if (number is equal to 3)
print “Three”
else
print “Other”
end_if
while (condition)
loop-body
end_while
Ex 3 : Write a program that reads and displays the age of 10 people (one after
another).
Note:
For this problem, we need away to count how many people whose age have been
processed (read and displayed). Therefore, we introduce a concept of counter, a
variable used to count the number of people whose age have been processed by
the program.
1. Algorithm
Ex 4 :
Write a n algorithm that will calculate and print the age of 10 persons, given
their birth year. If the age of the person is above 55, then the program will print
“Retired”, otherwise, the program will print “Still working”.
Ex 2 : Write a program the converts the input Celsius degree into its equivalent
Fahrenheit degree. Use the formula: F = (9/5) *C+32.
E10 : Write a program to compute the radius of a circle. Derive your formula from
the given equation: A=πr², then display the output.