+ All Categories
Home > Documents > Chapter 5 Data representation. Aim Explain how integers are represented in computers using:...

Chapter 5 Data representation. Aim Explain how integers are represented in computers using:...

Date post: 24-Dec-2015
Category:
Upload: marylou-jenkins
View: 242 times
Download: 3 times
Share this document with a friend
Popular Tags:
42
Chapter 5 Data representation
Transcript
Page 1: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Chapter 5

Data representation

Page 2: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Aim

• Explain how integers are represented in computers using:• Unsigned, signed magnitude, excess, and two’s complement notations

• Explain how fractional numbers are represented in computers• Floating point notation (IEEE 754 single format)

• Calculate the decimal value represented by a binary sequence in:• Unsigned, signed notation, excess, two’s complement, and the IEEE 754

notations.

• Explain how characters are represented in computers• E.g. using ASCII and Unicode

• Explain how colours, images, sound and movies are represented

Page 3: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Integer Representations

• Unsigned notation

• Signed magnitude notion

• Excess notation

• Two’s complement notation.

Page 4: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Unsigned Representation

Represents positive integers. Unsigned representation of 157:

Addition is simple:

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

position 7 6 5 4 3 2 1 0

Bit pattern 1 0 0 1 1 1 0 1

contribution 27 24 23 22 20

Page 5: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Advantages and disadvantages of unsigned notation

Advantages:• One representation of zero

• Simple addition

Disadvantages• Negative numbers can not be represented.

• The need of different notation to represent negative numbers.

Page 6: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Signed Magnitude Representation

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.

Page 7: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Example

Suppose 10011101 is a signed magnitude representation. The sign bit is 1, then the number represented is negative

The magnitude is 0011101 with a value 24+23+22+20= 29 Then the number represented by 10011101 is –29.

position 7 6 5 4 3 2 1 0

Bit pattern 1 0 0 1 1 1 0 1

contribution - 24 23 22 20

Page 8: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

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?

Page 9: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Signed-Summary

In signed magnitude notation, • the most significant bit is used to represent the sign.

• 1 represents negative numbers

• 0 represents positive numbers.

• The unsigned value of the remaining bits represent The magnitude.

Advantages:• Represents positive and negative numbers

Disadvantages: • two representations of zero,

• difficult operation.

Page 10: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Excess Notation

In excess notation:

• the value represented is the unsigned value with a fixed value subtracted from it.

• For n-bit binary sequences the value subtracted fixed value is 2(n-1).

• Most significant bit:

• 0 for negative numbers

• 1 for positive numbers

Page 11: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Excess Notation with n bits

1000…0 represent 2n-1 is the decimal value in unsigned notation.

Therefore, in excess notation:• 1000…0 will represent 0 .

Decimal valueIn unsigned

notation

Decimal valueIn excess notation

- 2n-1 =

Page 12: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Example (1) - excess to decimal

Find the decimal number represented by 10011001 in excess notation.• Unsigned value

• 100110002 = 27 + 24 + 23 + 20 = 128 + 16 +8 +1 = 15310

• Excess value:• excess value = 153 – 27 = 152 – 128 = 25.

Page 13: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Example (2) - decimal to excess

Represent the decimal value 24 in 8-bit excess notation.

We first add, 28-1, the fixed value• 24 + 28-1 = 24 + 128= 152

then, find the unsigned value of 152

• 15210 = 10011000 (unsigned notation).

• 2410 = 10011000 (excess notation)

Page 14: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

example (3)

Represent the decimal value -24 in 8-bit excess notation.

We first add, 28-1, the fixed value• -24 + 28-1 = -24 + 128= 104

then, find the unsigned value of 104• 10410 = 01101000 (unsigned notation).

• -2410 = 01101000 (excess notation)

Page 15: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Example (4) -- 10101 Unsigned

• 101012 = 16+4+1 = 2110

• The value represented in unsigned notation is 21 Sign Magnitude

• The sign bit is 1, so the sign is negative

• The magnitude is the unsigned value 01012 = 510

• So the value represented in signed magnitude is -510

Excess notation

• As an unsigned binary integer 101012 = 2110

• subtracting 25-1 = 16, we get 21-16 = 510.

• So the value represented in excess notation is 510.

Page 16: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Excess notation - Summary In excess notation, the value represented is the unsigned

value with a fixed value subtracted from it.• i.e. for n-bit binary sequences the value subtracted is 2(n-1).

Most significant bit:

• 0 for negative numbers .

• 1 positive numbers.

Advantages:• Only one representation of zero.

• Easy for comparison.

Page 17: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

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.

Page 18: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Properties of Two’s Complement Notation

Positive numbers begin with 0 Negative numbers begin with 1 Only one representation of 0, i.e. 0000 Relationship between +n and –n.

• 0 1 0 0 +4 0 0 0 1 0 0 1 0 +18

• 1 1 0 0 -4 1 1 1 0 1 1 1 0 -18

Page 19: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Two’s complement-summary In two’s complement the most significant for an n-bit number

has a contribution of –2(n-1). One representation of zero All arithmetic operations can be performed by using addition

and inversion. The most significant bit: 0 for positive and 1 for negative. Three methods can the decimal value of a negative number:

Method 1 decimal value of (n-1) bits, then subtract 2n-1

Method 2 - 2n-1 is the contribution of the sign bit.

Method 3 • Binary rep. of the corresponding positive number.• Let V be its decimal value.• - V is the required value.

Page 20: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Exercise - 10001011

Determine the decimal value represented by 10001011 in each of the following four systems.

1. Unsigned notation?

2. Signed magnitude notation?

3. Excess notation?

4. Tow’s complements?

Page 21: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Fraction Representation

• Floating point representation.

Page 22: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Floating Point Representation format

The exponent is biased by a fixed value

b, called the bias. The mantissa should be normalised,

e.g. if the real mantissa if of the form 1.f then the normalised mantissa should be f, where f is a binary sequence.

Sign Exponent Mantissa

Page 23: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Representation in IEEE 754 single precision

sign bit:• 0 for positive and,

• 1 for negative numbers

8 biased exponent by 127 23 bit normalised mantissa

 Sign Exponent Mantissa

Page 24: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Example (1)

5.7510 in IEEE single precision 5.75 is a positive number then the sign bit is 0. 5.75 = 101.11 * 20

= 10.111 * 21

= 1.0111 * 22

The real mantissa is 1.0111, then the normalised mantissa is0111 0000 0000 0000 0000 000

The real exponent is 2 and the bias is 127, then the exponent is

2 + 127=12910 = 1000 00012. The representation of 5.75 in IEE sing-precision is:

0 1000 0001 0111 0000 0000 0000 0000 000

Page 25: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Example (2)

which number does the following IEEE single precision notation represent?

The sign bit is 1, hence it is a negative number. The exponent is 1000 0000 = 12810

It is biased by 127, hence the real exponent is 128 –127 = 1.

The mantissa: 0100 0000 0000 0000 0000 000. It is normalised, hence the true mantissa is

1.01 = 1.2510 Finally, the number represented is: -1.25 x 21 = -2.50

1 1000 0000 0100 0000 0000 0000 0000 000

Page 26: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Single Precision Format

The exponent is formatted using excess-127 notation, with an implied base of 2• Example:

• Exponent: 10000111• Representation: 135 – 127 = 8

The stored values 0 and 255 of the exponent are used to indicate special values, the exponential range is restricted to 2-

126 to 2127

The number 0.0 is defined by a mantissa of 0 together with the special exponential value 0

The standard allows also values +/-∞ (represented as mantissa +/-0 and exponent 255

Allows various other special conditions

Page 27: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

In comparison

The smallest and largest possible 32-bit integers in two’s complement are only -232 and 231 - 1

23/4/19 PITT CS 1621 27

Page 28: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Range of numbersNormalized (positive range; negative is

symmetric)

00000000100000000000000000000000 +2-126× (1+0) = 2-126

01111111011111111111111111111111 +2127× (2-2-23)

smallest

largest

0 2-1262127(2-2-23)

Positive underflow Positive overflow

23/4/19 PITT CS 1621 28

Page 29: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Representation in IEEE 754 double precision format

It uses 64 bits• 1 bit sign

• 11 bit exponent biased by 1023.

• 52 bit mantissa

 Sign Exponent Mantissa

Page 30: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Character representation- ASCII ASCII (American Standard Code for Information Interchange)

It is the scheme used to represent characters.

Each character is represented using 7-bit binary code.

If 8-bits are used, the first bit is always set to 0

See (table 5.1 p56, study guide) for character representation in ASCII.

Page 31: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

ASCII – example

Symbol decimal Binary

7 55 00110111

8 56 00111000

9 57 00111001

: 58 00111010

; 59 00111011

< 60 00111100

= 61 00111101

> 62 00111110

? 63 00111111

@ 64 01000000

A 65 01000001

B 66 01000010

C 67 01000011

Page 32: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Character strings

How to represent character strings? A collection of adjacent “words” (bit-string units) can

store a sequence of letters

Notation: enclose strings in double quotes• "Hello world"

Representation convention: null character defines end of string• Null is sometimes written as '\0'

• Its binary representation is the number 0

'H' 'e' 'l' 'l' o' ' ' 'W' 'o' 'r' 'l' 'd' '\0'

Page 33: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Layered View of Representation

Textstring

Sequence ofcharacters

Character

Bit string

Information

Data

Information

Data

Information

Data

Information

Data

Page 34: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Unicode - representation ASCII code can represent only 128 = 27 characters. It only represents the English Alphabet plus some control

characters. Unicode is designed to represent the worldwide

interchange. It uses 16 bits and can represents 32,768 characters. For compatibility, the first 128 Unicode are the same as

the one of the ASCII.

Page 35: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Colour representation Colours can represented using a sequence of bits.

256 colours – how many bits?• Hint for calculating

• To figure out how many bits are needed to represent a range of values, figure out the smallest power of 2 that is equal to or bigger than the size of the range.

• That is, find x for 2 x => 256

24-bit colour – how many possible colors can be represented?• Hints

• 16 million possible colours (why 16 millions?)

Page 36: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

24-bits -- the True colour

• 24-bit color is often referred to as the true colour.

• Any real-life shade, detected by the naked eye, will be among the 16 million possible colours.

Page 37: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Example: 2-bit per pixel

4=22 choices• 00 (off, off)=white

• 01 (off, on)=light grey

• 10 (on, off)=dark grey

• 11 (on, on)=black

0 0

= (white)

1 0

= (dark grey)

10

= (light grey)

11

= (black)

Page 38: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Image representation

An image can be divided into many tiny squares, called pixels.

Each pixel has a particular colour. The quality of the picture depends on two factors:

• the density of pixels.

• The length of the word representing colours. The resolution of an image is the density of pixels. The higher the resolution the more information

information the image contains.

Page 39: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Representing Sound Graphically

X axis: time Y axis: pressure A: amplitude (volume) : wavelength (inverse of frequency = 1/)

Page 40: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Sampling

Sampling is a method used to digitise sound waves.

A sample is the measurement of the amplitude at a point in time.

The quality of the sound depends on:• The sampling rate, the faster the better

• The size of the word used to represent a sample.

Page 41: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Digitizing Sound

Zoomed Low Frequency Signal

Capture amplitude at these points

Lose all variation between data points

Page 42: Chapter 5 Data representation. Aim Explain how integers are represented in computers using: Unsigned, signed magnitude, excess, and two’s complement notations.

Summary Integer representation

• Unsigned,

• Signed,

• Excess notation, and

• Two’s complement. Fraction representation

• Floating point (IEEE 754 format )• Single and double precision

Character representation Colour representation Sound representation


Recommended