Meeting1-Block 1-Part 1

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 28

TM112: Introduction to Computing and

Information Technology 2

Meeting #1
Block 1 (Part 1 )
Binary data representation and computation
OU Materials, PPT prepared by Dr. Khaled Suwais
1
Edited by Dr. Ahmad Mikati
Contents

• Introduction
• 1.1 Representing integers and text in binary
• 1.2 Decimal numbers and some limitations of binary representations
• 1.3 Representing logic operations and logic circuits
• Summary

2
Introduction

• This part will provide you with a basic understanding of


how computers represent and process data.
• After studying it, you will be able to compare some of the
different binary representations of data and reason about
their efficiency.
• Also, you will appreciate that sometimes a particular
representation can lead to errors (with potentially far-
reaching consequences).

3
1.1 Representing integers and text in binary

• The printed symbols shown in Figure 1.1 provide


convenient representations of short and long flashes of
light or short and long bleeps of sound, which is how Morse
code is normally transmitted.

4
1.1 Representing integers and text in binary

• In any representation it is important that the symbols can


be distinguished from each other.
• Changes in electrical voltages or friction in mechanical
systems can cause random fluctuations, called noise,
which may distort how the symbol is perceived.
• In a binary system there are only two symbols, so it is
generally easier to make them different enough to be
distinguishable – for example, Morse code specifies that a
dash should be three times as long as a dot.

5
Binary representation systems in computers

• Some very early computers, such as the ENIAC (Electronic


Numerical Integrator and Computer), tried to represent
data using our usual base-10 system. So 0 volts was used
to represent the digit 0, 1 volt to represent the digit 1, and
so on, all the way up to 9 volts to represent the digit 9.
• Hence, a lot of circuitry was needed just in order to
distinguish between the different voltages, which took up
a lot of space and generated a lot of heat.
• The advantage of representing data in binary is that only
two ranges of voltage need to be detected.
6
Converting numbers from binary to decimal
notation

To convert a number from binary to decimal notation, we put the


number in the table and add up the values of each place value.
So to convert the binary number 1001 into decimal notation, we
can use the following table

Decimal number= 8+1=9

7
Converting numbers from decimal to binary
notation

8
Representing integers in binary
Unsigned integers

• In computer-speak, an unsigned integer is an integer that


is greater than or equal to zero.
• An unsigned integer is sufficient for any purpose where a
value does not become negative – for example, a counter
counting upwards from zero.
• The number of unsigned decimal values that we can
represent in binary depends on the number of bits we have
available. If there are 3 bits available, we can represent 2 3 =
8 values. If we want to include 0, this means that we can
encode all of the unsigned integers from 0 to 7 in three bits.
9
Representing integers in binary
Unsigned integers

• The largest decimal value that can be represented in 3 bits


is 7. This is one less than 23 (or, in mathematical notation,
23 – 1) because one of the 8 available codes has been used up
to represent 0.
• This scheme can be extended to systems with more bits.
• In general, if we have n bits, we can represent 2 unsigned
n

integers, and the largest integer that can be represented is


2n – 1.

10
Adding unsigned integers in binary notation

• In decimal notation, adding two positive integers is very


straightforward. The two values are added and the sign of the
result is automatically positive.
• Similarly, if the values are represented as two unsigned
integers in binary notation, their binary values can just be
added.
• So, to add two binary numbers by hand, we use the same
method as adding two decimal numbers. The numbers are
written one under the other, so that each column has the
same place value. Then the digits in each column are added,
column by column from the right, carrying digits as necessary.
11
Adding unsigned integers in binary notation

• To illustrate, here is the working to add the two unsigned


integers 110 and 101, where the ‘carry’ digit is shown in
blue below:

12
Sign-magnitude representation
Signed magnitude is the most intuitive method for representing the
unsigned numbers.
The MSB (Most Significant Bit) of a binary number is kept as the
“sign” of the number
MSB = 1: negative number
MSB = 0: positive number
The remaining bits represent the magnitude (or absolute value) of
the numeric value.

• So for our 3 bits, there would be 23 = 8 possible binary codes, which
could be used to encode positive and negative integers as shown in
Table 1.7.

13
Sign-magnitude representation
In an N bit word signed magnitude system
 1 bit is used for the sign of the number (MSB).
 N-1 bits are used for the magnitude of the number.
 The largest integer is 2N-1- 1
 The smallest integer is -(2N-1- 1)

Example: In an 8 bit word signed magnitude system give the decimal


representation of the following numbers: 00000001, 10000001
Answer:
•00000001:
-The MSB is 0: The number is positive
-The remaining 7 bits are: 00000012 = 110
-The decimal number is +1
•10000001:
-The MSB is 1: The number is negative
-The remaining 7 bits are: 00000012 = 110
-The decimal number is -1
14
1.1.5 Representing text in binary
• Most modern systems for encoding text derive in part from ASCII
(American Standard Code for Information Interchange, pronounced
‘askee’), which was developed in 1963.
• In the original ASCII system, upper-case and lower-case letters,
numbers, punctuation and other symbols and control codes (such as
a carriage return, backspace and tab) were encoded in 7 bits. As
computers based on multiples of 8 bits (or a byte) became more
common, the encoding system became an 8-bit system, and so could
be expanded to include more symbols.
• When binary numbers were assigned to each character in the original
ASCII system, careful thought was given to choosing sequences of
values for the characters of the alphabet and numerals that would
make it easy for a computer processor to perform common
operations on them. (These encodings were preserved in the 8-bit
15
system by simply padding out the leftmost bit with a 0.)
1.1.5 Representing text in binary

• Since 2007, the standard encoding system for characters has been
Unicode Transformation Format-8 (UTF-8) which uses a variable
number of bytes (up to 6) to encode characters in use across the
world. However, in order to maintain backward compatibility, the
original 127 ASCII codes are preserved in UTF-8.
16
Floating-point numbers and scientific
notation

• Consider the decimal number 2343.56. We could also write this


as 23.4356 × 102 OR 0.234356 × 104 or 234356.0 × 10–2.
• The decimal point can ‘float’ to any position as long as the
power of 10 is appropriate.
• Scientific notation is a special case of floating-point notation
where there is a single non-zero digit between 1 and 9
(inclusive) to the left of the decimal point.
• So the number 2343.56 can be represented in scientific notation
as 2.34356 × 103. Note that the exponent, 3, indicates that the
decimal point should be moved three places to the right to get
back the original decimal notation.
17
Floating-point numbers and scientific
notation

• The number –0.000654 in decimal notation can be written as


-6.54 × 10–4 in scientific notation. Here, the negative exponent
(–4) indicates that the decimal point should be moved 4 places
to the left to get back to the original decimal notation.
• Notice that scientific notation has three distinct parts, shown
in Figure 1.10:
• a sign
• an exponent (the power of 10)
• a mantissa (the decimal number part).

18
1.3 Representing logic operations and logic
circuits

• In the previous two sections, we have seen that we can use binary
encodings to represent numerical and textual data. We will now see
that operations, including arithmetical operations such as addition,
and comparison operations such as less than and equals, can be
encoded as one or more logic operations. These logic operations act
on the binary representations of the data.
• To move from the human to the computer view, the integers have to
be encoded as binary representations and the addition operator has
to be encoded as a sequence of logical operations that have what is
called the truth table.

19
1.3 Representing logic operations and logic
circuits

• A truth table for a logic operation lists all the possible


combinations of input values, and for each possibility gives the
output value for that operation. As the operations we will
consider will always be applied to binary encodings, each input
value must be either a 1 or a 0 and the result of the operation
must also always be a 1 or a 0.
• We will start by looking at the truth tables for three of the
fundamental logical operations defined by Boole. We will then
see how these basic operations can be used as building blocks
for the logic circuits that perform more complex operations.
By the end of this subsection, you will see how these simple
operations can be used to build a logic circuit to add two binary
numbers. 20
1.3 Representing logic operations and logic
circuits
The NOT operation
• One of the most fundamental operations we might want to perform is
•  to ‘flip’ a single bit – let’s call the bit a. So if is 1, we want the result to
be 0, and if is 0, we want the result to be 1. This operation is called
NOT  and is expressed as: or ’.
The behavior of NOT operator is characterized by the truth table
shown below:
To physically perform logic operations on
binary data in a computer, we need to use
electrical components. The components
that represent the most fundamental
operations are called logic gates, which
can be combined in a logic circuit in order
to create more complex operations.
The NOT truth table
21

The NOT logic gate


1.3 Representing logic operations and logic
circuits

• The AND operation


• Most logical operations involve two input values. A truth table for
two binary inputs, x and y, has more rows because there are four
possible permutations (or ways of combining) the two input values,
as shown in Table 1.19.

AND logic gate

AND truth table

22
1.3 Representing logic operations and logic
circuits

• The OR operation
• truth table for the logic operation OR (which Boole originally
designated by the symbol +) is shown below

OR logic gate

OR truth table
23
Building logic circuits

• Suppose we want to build a logic circuit with two inputs, A and B,


that tests if B is greater than A. The first step is to create a truth table
showing the desired outcomes: if B is greater than A, the result is 1
(True), otherwise the result is 0 (False).

24
Building logic circuits
• To translate this into a logic expression – that is a combination of
our logic operations (NOT, AND and OR) – we follow this algorithm.
• Identify the row where the outcome (B > A) is 1.
• If input A is 1, write A; otherwise write NOT A in the logic expression for
the selected row.
• If input B is 1, write B; otherwise write NOT B in the logic expression for
the selected row.
• Join these with an AND.
• The final equation will be the sum of all the deduced logic expressions.
This algorithm yields the answer given

Final equation: A’. B


25
Building logic circuits

• Here, the resulting logic expression NOT A AND B tells us that the
logic circuit that is equivalent to this truth table for each combination
of inputs can be constructed from two logic gates

• a NOT gate with A as an input, which gives an output of NOT A


• an AND gate that takes NOT A and B as inputs, which gives the
required result NOT A AND B as an output.
26
Building logic circuits

  the above circuit:


In
The output of gate 1 is:
The output of gate 2 is:
The output of gate 3 is:

27
1.3.4 What is inside a logic gate?
• How Logic gates are actually constructed , and what exactly is
inside a logic gate?
• A Logic gate is itself made up of a combination of more
fundamental components that act as on/off switches.
• In early computers, such devices were generally based on
various designs of vacuum tube (collectively called valves).
• In modern computers, they are based on transistors, which are
formed of layers of semiconducting material such as silicon.

28
A ‘pluggable’ unit made of valves from A chip containing six inverters
an IBM computer of the mid-1950s

You might also like