Sei sulla pagina 1di 41

College of Computer Science

Chapter 2
Data representations in Computer Systems

Course CNE211 : Computer Design & Organization

Text Books :
-- W. Stallings, Computer Organization and Architecture: Designing for Performance,
8’th Edition, Prentice -Hall, Inc
-- Computer System Architecture by M. Moris Mano ,3rd Edition Published by
Prentice Hall International

1439/1440
Computer Design & Organization

Contents

> Data types


> Number systems
> Converting Numbers Between Bases
> Signed Integer Representation
> Integer Arithmetic
> Floating-point representations
> Alphanumeric Representations
> Error detection codes
2
Computer Design & Organization

Data types (1)

> The data types stored in digital computers may


be classified as being one of the following
categories :
– numbers used in arithmetic computations,
– letters of the alphabet used in data processing, and
– other discrete symbols used for specific purposes.

> All types of data are represented in computers


in binary-coded form.

3
Computer Design & Organization

Data types (2)

> A bit is the most basic unit of information in a


computer.
• It is a state of “on” or “off” in a digital circuit.
• Sometimes they represent high or low voltage

> A byte is a group of eight bits.. It is the


smallest possible addressable unit of computer storage.
> A word is a contiguous group of bytes.
— Words can be any number of bits or bytes.
— Word sizes of 16, 32, or 64 bits are most common.

4
Computer Design & Organization

Positional Numbering Systems (1)

— The binary system is also called the base-2 system.


(101100.011)
— Our decimal system is the base-10 system. It uses
powers of 10 for each position in a number. (975.3)
— Any integer quantity can be represented exactly
using any base (or radix). (3077 octal or 2BAD hex)

5
Computer Design & Organization

Positional Numbering Systems (2)

> Key principle of numbering systems


> Weight assigned to digit
— Based on position in number
> Steps for base 10
— Determine positional value of each digit by raising 10 to position
within number
> Radix point
— Divides fractional portion from the whole portion of a number

6
Computer Design & Organization

Positional Numbering Systems (2)

> The decimal number 947 in powers of 10 is:

9 × 10 2 + 4 × 10 1 + 7 × 10 0

> The decimal number 5836.47 in powers of 10 is:

5 × 10 3 + 8 × 10 2 + 3 × 10 1 + 6 × 10 0
+ 4 × 10 -1 + 7 × 10 -2

7
Computer Design & Organization

Positional Numbering Systems (3)

> The binary number 11001 in powers of 2 is:

1×24+1×23+0×22 +0×21+1×20
= 16 + 8 + 0 + 0 + 1 = 25
> When the radix of a number is something other
than 10, the base is denoted by a subscript.
— Sometimes, the subscript 10 is added for
emphasis:
110012 = 2510

8
Computer Design & Organization

Converting Numbers Between Bases

Octal(base 8)

Decimal(base 10) Binary(base 2)

Hexadecimal
• We normally convert to base 10
(base16)
because we are naturally used to the decimal number system.
• We can also convert to other number systems

9
Computer Design & Organization

Converting Numbers Between Bases

> Converting 190 to base 3...


— First we take the number that
we wish to convert and divide
it by the radix in which we
want to express our result.
— In this case, 3 divides 190
63 times, with a remainder of
1.
— Record the quotient and the
remainder.

10
Computer Design & Organization

Converting Numbers Between Bases

> Converting 190 to base 3...


— 63 is evenly divisible by 3.
— Our remainder is zero, and
the quotient is 21.

11
Computer Design & Organization

Converting Numbers Between Bases

> Converting 190 to base 3...


— Continue in this way until the
quotient is zero.
— In the final calculation, we note
that 3 divides 2 zero times with
a remainder of 2.
— Our result, reading from
bottom to top is:
19010 = 210013

12
Computer Design & Organization

Hexadecimal representation

> It is difficult to read long strings of binary


numbers-- and even a modestly-sized
decimal number becomes a very long binary
number.
— For example: 110101000110112 = 1359510

> For compactness and ease of reading, binary


values are usually expressed using the
hexadecimal, or base-16, numbering
system.

13
Computer Design & Organization

Converting between Base 16 and Base 2

> The hexadecimal numbering system uses


the numerals 0 through 9 and the letters A
through F.
— The decimal number 12 is C16.
— The decimal number 26 is 1A16.
> It is easy to convert between base 16 and
base 2, because 16 = 24. all we need to do is
group the binary digits into groups of four.

14
Computer Design & Organization

Converting between Base 16, 8 and Base 2

> Using groups of hextets, the binary number


110101000110112 (= 1359510) in hexadecimal is:

> Octal (base 8) values are derived from binary by


using groups of three bits (8 = 23):

Octal was very useful when computers used six-bit


words.
15
Computer Design & Organization

Example

> Convert 101011110110011 to


1. octal number
2. hexadecimal number

16
Computer Design & Organization

Example

1. Each 3 bits are converted to octal :


(101) (011) (110) (110) (011)
↓ ↓ ↓ ↓ ↓
5 3 6 6 3
101011110110011 = (53663)8

2. Each 4 bits are converted to hexadecimal:


(0101) (0111) (1011) (0011)
↓ ↓ ↓ ↓
5 7 B 3
101011110110011 = (57B3)16
Conversion from binary to hexadecimal is similar except that
the bits divided into groups of four.
17
Computer Design & Organization

Signed Integer Representation

> Is a representation of negative numbers possible?


> Unfortunately:
— you can not just stick a negative sign in front of a binary
number. (it does not work like that)
> There are three methods used to represent
negative numbers.
Signed magnitude notation
Excess notation
Two’s complement notation

18
Computer Design & Organization

Signed Magnitude Representation

> Unsigned: - and + are the same.


> In signed magnitude
– the left-most bit represents the sign of the integer.
– 0 for positive numbers.
– 1 for negative numbers.

> The remaining bits represent to magnitude of


the numbers.

19
Computer Design & Organization

Example

> Suppose 10011101 is a signed magnitude representation.


> The sign bit is 1, then the number represented is negative

position 7 6 5 4 3 2 1 0
Bit pattern 1 0 0 1 1 1 0 1
contribution 24 23 22 20
-
> The magnitude is 0011101 with a value 24+23+22+20= 29
> Then the number represented by 10011101 is –29.

20
Computer Design & Organization

Exercise 1

1. 3710 has 0010 0101 in signed magnitude notation. Find the


signed magnitude of –3710 ?

2. Using the signed magnitude notation find the 8-bit binary


representation of the decimal value 2410 and -2410.

3. Find the signed magnitude of –63 using 8-bit binary


sequence?

21
Computer Design & Organization

Disadvantage of Signed Magnitude

> Addition and subtractions are difficult.


> Signs and magnitude, both have to carry out the
required operation.
> They are two representations of 0
– 00000000 = + 010
– 10000000 = - 010
– To test if a number is 0 or not, the CPU will need to see
whether it is 00000000 or 10000000.
– 0 is always performed in programs.
– Therefore, having two representations of 0 is inconvenient.

22
Computer Design & Organization

Two’s Complement Notation

> The most used representation for integers.


— All positive numbers begin with 0.
— All negative numbers begin with 1.
— One representation of zero
– i.e. 0 is represented as 0000 using 4-bit binary sequence.

23
87611 = 87610 + 1
Computer Design & Organization

Floating-Point Representation (1)

In decimal notation we can get around this problem using


scientific notation or floating point notation.

Number Scientific notation Floating-point


notation
1,245,000,000,000 1.245 1012 0.1245 1013

0.0000001245 1.245 10-7 0.1245 10-6

-0.0000001245 -1.245 10-7 -0.1245 10-6

24
Computer Design & Organization

Floating-Point Representation (2)

> Storage technique based on floating-point notation


— Example: 1.345E+5
— 1.345 = mantissa, E = exponent, + 5 moves decimal
> IEEE-754 specification
— Uses binary mantissas and exponents
> Implementation details are part of advanced study

25
Computer Design & Organization

Data Types: Alphanumeric

> Computers store characters according to standards


> ASCII
— Represents characters with 7-bit pattern
— Provides for upper- and lowercase English letters, numeric
characters, punctuation, special characters
— Accommodates 128 (27) different characters
> Globalization places upward pressure
— Extended ASCII: allows 8-bit patterns (256 total)
— Unicode: defined for 16-bit patterns (34,168 total)

26
Computer Design & Organization

Sample standard ASCII characters

27
Computer Design & Organization

Error Detection Codes

> It is physically impossible for any data recording or


transmission medium to be 100% perfect 100% of the
time over its entire expected useful life.
> As more bits are packed onto a square centimeter of
disk storage, as communications transmission speeds
increase, the likelihood of error increases-- sometimes
geometrically.
> Thus, error detection and correction is critical to
accurate data transmission, storage and retrieval.

28
Computer Design & Organization

Cyclic redundancy checking (CRC)

> Cyclic redundancy checking (CRC) codes provide error


detection for large blocks of data.

> Checksums and CRCs are examples of systematic error


detection.

> In systematic error detection a group of error control bits


is appended to the end of the block of transmitted data.

> This group of bits is called a syndrome.

> CRCs are polynomials over the modulo 2 arithmetic


field.

29
Computer Design & Organization

Cyclic redundancy checking (CRC)

> Modulo 2 arithmetic works like clock arithmetic.


> In clock arithmetic, if we add 2 hours to 11:00, we get
1:00.
> In modulo 2 arithmetic if we add 1 to 1, we get 0. The
addition rules couldn’t be simpler:

0+0=0 0+1=1
1+0=1 1+1=0

30
Computer Design & Organization

Cyclic redundancy checking (CRC)

> Find the quotient and


remainder when 1111101 is
divided by 1101 in modulo 2
arithmetic.
— As with traditional division, we
note that the dividend is divisible
once by the divisor.
— We place the divisor under the
dividend and perform modulo 2
subtraction.

31
Computer Design & Organization

Cyclic redundancy checking (CRC)

> Find the quotient and


remainder when 1111101 is
divided by 1101 in modulo 2
arithmetic…
— Now we bring down the next bit
of the dividend.
— We see that 00101 is not
divisible by 1101. So we place a
zero in the quotient.

32
Computer Design & Organization

Cyclic redundancy checking (CRC)

> Find the quotient and


remainder when 1111101 is
divided by 1101 in modulo 2
arithmetic…
— 1010 is divisible by 1101 in
modulo 2.
— We perform the modulo 2
subtraction.

33
Computer Design & Organization

Cyclic redundancy checking (CRC)

> Find the quotient and


remainder when 1111101 is
divided by 1101 in modulo 2
arithmetic…
— We find the quotient is 1011, and
the remainder is 0010.
> This procedure is very useful
to us in calculating CRC
syndromes.

Note: The divisor in this example corresponds to


a modulo 2 polynomial: X 3 + X 2 + 1.

34
Computer Design & Organization

Cyclic redundancy checking (CRC)

> Suppose we want to transmit the


information string: 1111101.
> The receiver and sender decide to
use the (arbitrary) polynomial
pattern, 1101.
> The information string is shifted
left by one position less than the
number of positions in the divisor.
> The remainder is found through
modulo 2 division (at right) and
added to the information string:
1111101000 + 111 = 1111101111.

35
Computer Design & Organization

Cyclic redundancy checking (CRC)

> If no bits are lost or


corrupted, dividing the
received information string by
the agreed upon pattern will
give a remainder of zero.
> We see this is so in the
calculation at the right.
> Real applications use longer
polynomials to cover larger
information strings.
— Some of the standard poly-
nomials are listed in the text.

36

Potrebbero piacerti anche