Uploaded by Kyuni Danboyi

COMPUTER ARCHITECTURE LECTURE NOTE WEEK 6 (1)

advertisement
TOPIC
DATA REPRESENTATION IN A COMPUTER
6
LEARNING OUTCOMES
After completing the class, the student will be able to
understand:
 Data Representation in a Computer
 Bits
 Byte
 Nibble
 Word
 Characters
 Picture and Graphic
 Sound
 Program
 Integers
 How Does the computer know what a Byte Represent
 Converting binary numbers to decimal number
 Binary Arithmetic Operation
 Representation of numbers as an integer
 9’complement
 10’complement
 Floating-Point Representation
 Fixed Point Representation

DATA REPRESENTATION IN A COMPUTER
We have all seen computers do seemingly miraculous things with all kinds of sounds,
pictures, graphics, numbers, and text. It seems that we can build replies of part of our
world inside the computer. You might think that this amazing machine is also
amazingly complicated. It really is not. In fact, all are constructed from simple ON/OFF
switches millions of them, but really nothing much more complicated than a switch.
The trick is to take all of the real-world sound, pictures, number etc. data that we want
in the computer and convert it into the kind of data that can be represented in
switches.
Computers are electronic machines. The computer use electricity, not mechanical
parts, for its data processing and storage. Electricity is plentiful, moves very fast
through wires, and electrical part fail less much less frequently that mechanical parts.
The computer does have some mechanical parts, like its disk drive (which are often the
source for computer failures), but the internal data processing and storage is
electronic, which is fast and reliable (as king as the computer is plugged in).
Electricity can flow through switches; if the switch is closed, the electricity flows; if the
switch is pen, the electricity does not flow. To process real-world data in the
computer, we need a way to represent the data in switches. Computers do this
representation using a binary coding system.
Binary and Switches: Binary is mathematical number system: a way of counting. We
have all leaned to count using ten digits:0-9. Once probable reason is that we have ten
fingers to represent numbers. The computer has switches to represent data and
switches have only two states: ON and OFF. Binary has two digits to do counting: 0 and
1 a natural fit to the two states of a switch (0=OFF, 1=ON).
Grouping bits together: widely in reference to computer memory and data size.
 BITES: can be define as either a binary, which can be 0, or 1. it is the basic unit of
data or information in digital computers.
 BYTE: a group of bits (8 bits) used to represent a character. A byte is considered
as the basic unit of measuring memory size in computer.
 NIBBLES: is half a byte, which is usually a grouping of 4 bytes.
 WORD: two or more bits make a word. The term word length is used as the
measures of the number of bits in each word. For example; a word can have a
length of 16 bits, 32 bits, 64 bits etc.
Computer designers use eight bit chunks called bytes as the basic unit of data. The
byte is implemented with switches.
Computer manufactures express the capacity of memory and storage in terms of the
number of bytes it can hold. The number of bytes can be expressed as kilobytes. Kilo
represents 2 to the length power, or 1024. Kilobyte is abbreviated KB, or simply K.
Memory of a 640K computer can store 640*1024, or 655,360 bytes. Memory capacity
may also be expressed in MB (1024*1024), GB, TB.
Kb is not KB
As show above computer represent every data in 0s and 1s so, how this can be do, will
see one by one in following sections.
 Characters: how a computer represent characters must convert into binary. This
can be done using American Standard Code for Information interchange
(ASCII), ASCII-8, Common version use 8 bits per character and represent 256 different
characters, for example, the better A represented by 01000001.
 Pictures and Graphics: photographs are a big grid of colored dots. Computer
graphic data like pictures, frames of a movie, drawings, or frames of an
animation are represented by a grid of pixels, pixel is short for pictures element.
In simple graphics (those without many colors), a byte can represent a single
pixel in a graphics representation called grayscale each pixel is a shade of grey
from block at one extreme to white at the other, since eight bytes can hold 256
different integers (0-255 as described a few paragraphs ago), a pixel in one byte
can be one of 256 shades of grey (usually with 0 being white and 255 being
black). Modern video games and colorful graphics use several bytes for each
pixel (Nintendo 64 uses eight bytes=64 bits for each pixel to get a huge array of
possible colors). A scanned photograph or a computer drawing is thus stored as
thousand of bytes – each byte, or collection of bytes, representing a pixel.
We saw that computer manufacturers got together and agreed how characters will be
represented (the ASCII code). For graphics, there are several similar standards or
formats. Two common pictures formats used on the internet are JPEG and GIF. These,
like ASCII, are agreed – upon common coding of pixels in bytes,
 Sound: sound occurs naturally as an analog wave, as shown in figure below
Most current electronic speakers, the mean that we use to electronically reproduce
sound, also produce analog waves. However, as we have seen, all date in the
computer is digital and must be processed in bytes. The process of taking analogs data,
such as sound, and making it digital is called analog to digital conversation. Many
music CD’s from old original analog recordings on tapes were converted to digital to be
placed on a CD (a CD is digital; it is just a collection of bits with a small hole burned in
the CD representing a I and hole representing a 0).current music CD’s have the analog
to digital conversion done in the recording equipment itself, which produces better
conversion.
To convert an analog wave into digital, converters use a process called sampling. They
sample the height of the sound wave at regular intervals of time, often small fraction
of a second. If one bytes is used to hold a single sample of an analog wave. Then the
wave can be one of 256 different heights (0 being the lowest height and 255 being the
highest). These highest represent the decided level of the sound. Thus a spoken word
might occupy several hundred bytes – each being a sample of the sound wave of the
voice at a small fraction of a second. If these 100 bytes were sent to a computer’s
speaker, the spoken word would be reproduced.
Like ASCII for characters and GIF and JPEG for pictures, sound has agreed-upon
formats for representing sample in bytes. WAV is a common format on the internet.
 Program: collection of instructions that someone wrote to tell the computer to
perform the task that the software is meant to do. Each instruction is a byte, or
a small collection of bytes. If a computer used one byte for an instruction, it
could have up to 256 instructions. Later we will look at what these instructions
are, but for now, you should realize that a byte could also be a computer’s
instruction. The conversion of instruction to bytes is shown in figure below.
The programming process allows humans to write instructions in an English-like way. A
software program called a compiler then transforms the English-like text into bytes for
instructions that the computer understands
Like all other kind of data, there are agreed-upon formats for computer instruction
too. Once reason that Macintosh computer programs do not run natively on PCcompatible (Intel-based) computers, is that Macintoshes and intel PCs use different
formats for coding instructions in bytes.
 Integers: integer numbers are represented by counting in binary. In decimal we
start from 0 to count and when we reached 9 the end of decimal place and we
use two digit to count by putting a digit in the “tens place” and starting over
again using our 10 digits. Thus, the decimal number 10 is a 1 in the “tens place”
and zero in the “ones place”. And if we need three digits, like 122, we use a third
digit in the “hundred’s place”.
We do a similar thing to count in binary, except now we only have twodigits: 0 and 1.
So we start with 0, then 1, then we run out of digits, so we need to use two digits to
keep counting. We do this by putting a 1 in the “two’s place” and then using our two
digits. Thus two is 10 binary: a 1 in the “two’s place” and a 0 in the “one’s place”.
Three is 11: a1 in the “two’s place” and a 1 in the “one’s place”. We run out of digits
again! Thus, four is 100: a 1 in the “four’s place” a 0 in the “two’s place” a 0 in the
“one’s place”.
 How Does The Computer Know What a Byte Represents?
We have seen that the byte:
Can represent the integer 67, the character ‘C’, a pixel with darkness level 67, a sample
of a sound with decibel level 67, or instructions. The are other types of data that a byte
can represent too. If that same byte can be all of those different types of data, how
does the computer know what type it is? The answer is the context in which the
computer uses the byte. If it sends the byte to a speaker, the 67th level of sound is
produced. If it sends the byte to a monitor or printer, a pixel with the 67th level of
darkness is produced, etc. More accurately, if the byte were coded with a standard
coding technique, like ASCII for characters, GIF for pictures, and WAV for sounds, then
when the computer sends the byte to a device, the data corresponding to that coding I
produces by the device.
Number system
1. Decimal: base (radix) is 10
2. Hexal: base (radix) is 60
3. Octal: base (radix) is 8
4. Binary: base (radix) is 2
They are the way of number representation. However, in computer only binary can
be use and other must converted into the binary. Its has proved difficult to develop
devices that can understand natural language directly due to the complexity of natural
languages. However, it is easier to construct electric circuits based on the binary or ON
and OFF logic. All forms of data can be represented in binary system format. Other
reasons for the use of binary are that digital devices are more reliable, small and use
less energy as compared to analog devices, this is the main reasons to study binary
number system.
1. Decimal number system
The term decimals is derived from a Latin prefix deci, which means ten. Decimal
numbers system has ten digits ranging from 0-9. Because this system has ten digits: it
is also called a base ten number system or denary number system.
o A decimal number should always be written with a subscript 10 e.g, X10
o But since this is the most widely used number system in the world, the subscript
is usually understood and ignored in written work. However , when many
number system are considered together, the subscript must always be put so as
to differentiate the number system.
o The magnitude of a number can be considered using these parameters.
o Absolute value
o Place value or positional value
o Base value
 The absolute: value is the magnitude of a digit in a number. For
example digit 5 in 7458 has an absolute value of 5 according to its
value in the number line.
 The place value: of a digit in a number refers to the position of the
digit in that number i.e. whether, tens, hundred, thousands, etc.
 The total value: of a number is the sum of the place value of each
digit making the number.
 The base value: of a number also known as the radix, depends on
the type of the number systems that is being used. The value of any
number depends on the radix. For example the number 10010 is not
equivalent to 1002.
2. Binary Number System
It uses two digit namely, 1 and 0 to represent numbers, unlike in decimal numbers
where the place value goes up in factors of ten binary system, the place values
increase by the factor of 2binary numbers are written as X2.consider a binary
number such as 10112. The right most digits has a place value of 1 x 20 while the left
most has a place value of 1 x 23.
3. Octal Number System
Consists of eight digits ranging from 0-7, the place value of octal numbers goes up in
factors of eight from right to left.
4. Hexadecimal Number System
This is a base 16 number system that consists of sixteen digits ranging from 0-9 and
letters A-F where A is equivalent to 10,B to 11 up to F which is equivalent to 15 in base
ten system. The place value of hexadecimal numbers goes up in factors of sixteen. A
hexadecimal number can be denoted using 16 as a subscript or capital letter H to the
right of the number. For example, 94B can be written as 94B16 or 94BH.
 Converting binary numbers to decimal numbers
 To convert a binary number to a decimal number, we proceed as follows:




First write the place values starting from the right hand side.
Write each digit under its place value.
Multiply each digit by its corresponding place value.
Add up the products. The answer will be the decimal number in base ten.
 Example converting 39 to binary
 And if the decimal number has fraction part multiply by 2 till fractional
subsequent product is 0 or start to repeat itself.
o And grouping the carry (left of the decimal point) from first
(begunning) to last (end)
o Example: convert 0.625 to binary
o 0.625 x 2 – 1.25
0.25
with a carry of 1
o 0.25 x 2
=
0.50
with a carry of 0
o 0.50 x 2
=
1.00
with a carry of 1
o 0.625 – 0.101
o If the decimal is like39.625 and need to convert binary. This can be
done by separating before the decimal and after the decimal then
combine. 100111.101
 Converting Octal to Binary
 Work from left to the right, each octal number is represented using three
digits and then continued; we get the final binary equipment.
 Example convert 3218 to binary equipment
 3 – 011
 2 – 010
 1 – 001
 Combining the three from left to right 011010001
 Converting Binary to Octal
 Grouping the binary number by three digits sharing from right to left and
take its decimal equipment.
 Example convert 011010001 to octal equipment
 011 = 3
 010 = 2
 001 = 1
 Then 3218 is the equipment octal.
 Converting Hexadecimal to binary
 Working from left to right ,each hexa number is represented using four
digits and then combined; we get the final binary equipment.
 Example convert DI to binary
 D = 1101
 I = 0001
 Combining the two from left to right 11010001
 Converting Binary to Hexadecimal
 Grouping the binary number by four digits from right to left and take its
decimal equipment.
 Example convert 11010001 to hexadecimal equipment
 1101 – D
 0001 – I
 Then DI16 is the hexa equipment
 Converting Octal to Decimal
 The each steps binary to decimal convertion except radix difference
 Example convert 5128 to decimal equipment
Place value 82 81 80
648 1
Octal digit 5 1 2
 Write each number under its place value
 Multiply each number by its place value
 Converting Hexadecimal Number to Decimal Number
To convert hexadecimal number to base 10 equipment we proceed as follows:
First, write the place value sharing from the right hand side.
1. If a digit is a letter such as ‘A’ write its decimal equivalent
 Multiply each hexadecimal digit with its corresponding place value and
then add the product.
 The following example illustrate how to convert hexadecimal number to a
number
Example
Convert the hexadecimal number 11116 its to binary equivalence
Solution
Place each number under its place value.
 Binary Arithmetic Operation
 in arithmetics, the four basic arithmetic applied on numbers are
addition, subtraction, multiplication and division.
 In computers, the same operations are perform inside processing unit by
the arithmetic and logic unit (ALU).however, the arithmetic and logic
unit cannot perform binary subtraction directly. It perform binary
subtractions using a process known as for multiplication and division,
the arithmetic and logic unit uses a method called shifting before adding
the bits.
 Representation of number as an integer
 When an integer binary number is positive, the sign is represented by 0
and the magnitude by a positive number.
 When the number is negative, the sign is represented by I but the rest of
the number may be represented in one of three possible ways:
1. Signed magnitude representation
2. Signed 1’s complement representation
3. Signed 2’s complement representation
Example: Consider the signed number 14 stored in an 8 bit register.
+14 is represented by a sign bit of 0 in the leftmost position followed by the binary
equivalent of 14 00001110. Note that each of the eight bits of the register must
have a value and, therefore, 0’s must be inserted in the most significant position
following the sign bit.
Although there is only one way to represent +14, there are three different ways
represent -14 with eight bits.
Sign bit
In signed magnitude representation
1
0001110
In signed 1’s complement representation
1
1110001
In signed 2’s complement representation
1
1110010
 The signed magnitude representation of -14 obtained from +14 by completing
only the sign bit.
 The signed 1’s complement representation of -14 is obtained by complementing
all the bits of +14, including the sign bit.
 The signed 2’s complement representation is obtained by taking the 2’s
complement of the positive number, including its sign bit.
1. Signed magnitude representation
In this representation if we have it digits the absolute value is 2n – 1 and 1 digit for
sign 0 for positive or 1 for negative. And zero two representations both positive and
negative. This ambiguity makes its method slow. For example if you have 4 bits
representation in signed magnitude as follows:
 Performing arithmetic from this representation is difficult and dependent on the
sign bit which is the left most bit if it is 0 the number is positive and if it is 1 the
number is negative.
 Because of this ambiguity it is not use today’s.
 Example: 1-6
 1 === 0001
 -6 === 1110
 Sum ===1111 – 7 but the result must be -5 this is why this method is complex
however, if the numbers are both positive no problem can add simply
 Example 5 + 6
 5 === 0101
 6 === 0110
 Sum = 1011
2. Signed 1’s complement representation
 This method can minimize the drawback of signed magnitude problems. Even
though it has its own drawback that is deby of operation
 1’s complement of the number can be obtained by changing the bit that is 1 into
0, 0 into 1 or subtract all bits from all 1’s
 Example 1’s complement of 0 in four bits is 1111. How?
 0 in four bits is – 0000
 The change 0 into 1 = 1111
 Or subtract from all 1’s

1111
0000
1111 which is the same result






Example 6 – 2 which is equal to 6+(+2)
6 == 0110
-2 == 1101
Result = 10011.there is carry bit and it has to be add from right side.
Therefore 0011 + 1 is 0100 the correct answer.
These adding of carry bit causes delay and decreased the performance. So
we need other method better than this is 2’s complement.
3. Signed 2’s complement representation
 This representation can solve the drawback of the method those
described above.
 The first bit absolute is negative such as -0000 -1*23+0*22+0*21+0*20 =
-8 like this the following four bits example has given for further example
in 2’s complement.
 Example 6-2 which is 6+(2)
 6 = 0110
 -2 = 1110, that is different in signed magnitude, I’s complement and
here the best method is the one,
 Therefore 6+(-2) is 10100 there is carry and you have to discard it
rather than adding again like in I’s complement operation.
 So addition and subtraction can be done like these. The expression
is like X – Y = X + (-Y).
Note: generally complement is complement is r complement and r-1 complement.
The r complement such as 10 for decimal such as 2 for binary number system and r-1
complement such as 9 complement for decimal and 1 complement for binary number
system.
 9’complement:
To form the 9’s complement of decimal number each digit of a decimal number is
subtracted from 9, the result so obtain is known 9’s complement of the number.
EX: find 9’s complement of decimal number 37(10)
Solu : 37(10)= 9’s complement ?
9’s complement of 37 is
99 – 37 = 62.
Like that…...3977(10) = 9’s complement of 3977 is 9999 – 3977 = 6022.
 10’s complement:
The 10’s complement of a decimal number is equal to the 9’s complement of the
number plus 1. 10’s complement of 37 is 99 – 37 = 62 + 1 = 63.
Overflow:
When two number of a digit each are added and the sum occupies in 1 digits, we
say that an overflow occurred.
An overflow is a problem in digit computers because the width of registration is finite.
Download