Download presentation

Published byRichard Cox Modified over 4 years ago

1
**Data Representation How integers are represented in computers?**

How fractional numbers are represented in computers? Calculate the decimal value represented by a binary sequence. How to determine the binary sequence that represent a decimal number? Explain how characters are represented in computers? Explain how colours, images and sound are represented in computers?

2
Binary numbers Binary number is simply a number comprised of only 0's and 1's. Computers use binary numbers because it's easy for them to communicate using electrical current is off, 1 is on. You can express any base 10 (our number system -- where each digit is between 0 and 9) with binary numbers. The need to translate decimal number to binary and binary to decimal. There are many ways in representing decimal number in binary numbers. (later)

3
**How does the binary system work?**

It is just like any other system In decimal system the base is 10 We have 10 possible values 0-9 In binary system the base is 2 We have only two possible values 0 or 1. The same as in any base, 0 digit has non contribution, where 1’s has contribution which depends at there position.

4
Example = = 3*104+4*102+5*100 = =1*24+1*22+1*20

5
**Examples: decimal -- binary**

Find the binary representation of Find the decimal value represented by the following binary representations:

6
**Examples: Representing fractional numbers**

Find the binary representations of: 0.510 0.7510 Using only 8 binary digits find the binary representations of: 0.210 0.810

7
**Representation of Numbers**

Representing whole numbers Unsigned notation Signed magnitude notion Excess notation Two’s complement notation. Representing fractions Fixed point representation Floating point representation Normalisation IEEE Standard.

8
**Integer Representations**

All data in computers are represented in terms of 1s and 0s. Any integer can be represented as a sequence of 1s and 0s. Several ways of doing this.

9
**Unsigned Representation**

Represents positive integers. Unsigned representation of 157: Addition is simple: = position 7 6 5 4 3 2 1 Bit pattern contribution 27 24 23 22 20

10
**Advantages and disadvantages of unsigned notation**

One representation of zero Simple addition Disadvantages Negative numbers can not be represented. The need of different notation to represent negative numbers.

11
**Representation of negative numbers**

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

12
**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.

13
**Example - Suppose 10011101 is a signed magnitude representation.**

The sign bit is 1, then the number represented is negative The magnitude is with a value = 29 Then the number represented by is –29. position 7 6 5 4 3 2 1 Bit pattern contribution - 24 23 22 20

14
Exercise 1 3710 has in signed magnitude notation. Find the signed magnitude of –3710 ? Using the signed magnitude notation find the 8-bit binary representation of the decimal value 2410 and Find the signed magnitude of –63 using 8-bit binary sequence?

15
**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 = = To test if a number is 0 or not, the CPU will need to see whether it is or 0 is always performed in programs. Therefore, having two representations of 0 is inconvenient.

16
**Signed-Summary In signed magnitude notation, Advantages:**

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.

17
**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

18
**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 value In unsigned notation Decimal value In excess notation - 2n-1 =

19
**Example (1) - excess to decimal**

Find the decimal number represented by in excess notation. Unsigned value = = = 15310 Excess value: excess value = 153 – 27 = 152 – 128 = 25.

20
**Example (2) - decimal to excess**

Represent the decimal value 24 in 8-bit excess notation. We first add, 28-1, the fixed value = = 152 then, find the unsigned value of 152 15210 = (unsigned notation). = (excess notation)

21
**example (3) Represent the decimal value -24 in 8-bit excess notation.**

We first add, 28-1, the fixed value = = 104 then, find the unsigned value of 104 10410 = (unsigned notation). -2410 = (excess notation)

22
**Example (4) -- 10101 Unsigned Sign Magnitude Excess notation**

= = 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 = 510 So the value represented in signed magnitude is -510 Excess notation As an unsigned binary integer = 2110 subtracting = 16, we get = 510. So the value represented in excess notation is 510.

23
**Advantages of Excess Notation**

It can represent positive and negative integers. There is only one representation for 0. It is easy to compare two numbers. When comparing the bits can be treated as unsigned integers. Excess notation is not normally used to represent integers. It is mainly used in floating point representation for representing fractions (later floating point rep.).

24
**Exercise 2 Find 10011001 is an 8-bit binary sequence.**

Find the decimal value it represents if it was in unsigned and signed magnitude. Suppose this representation is excess notation, find the decimal value it represents? Using 8-bit binary sequence notation, find the unsigned, signed magnitude and excess notation of the decimal value ?

25
**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.

26
**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.

27
**Two’s Complement Notation with 4-bits**

Binary pattern Value in 2’s coml.not.

28
**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.

29
**Advantages of Two’s Complement Notation**

It is easy to add two numbers. + + Subtraction can be easily performed. Multiplication is just a repeated addition. Division is just a repeated subtraction Two’s complement is widely used in ALU

30
**Evaluating numbers in two’s complement notation**

Sign bit = 0, the number is positive. The value is determined in the usual way. Sign bit = 1, the number is negative. three methods can be used: 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.

31
**Example- 10101 in Two’s Complement**

The most significant bit is 1, hence it is a negative number. Method 1 0101 = (+5 – 25-1 = 5 – 24 = 5-16 = -11) Method 2 Method 3 Corresponding + number is = = 11 the result is then –11.

32
**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.

33
Exercise Determine the decimal value represented by in each of the following four systems. Unsigned notation? Signed magnitude notation? Excess notation? Tow’s complements?

34
**Fraction Representation**

To represent fraction we need other representations: Fixed point representation Floating point representation.

35
**Fixed-Point Representation**

old position New position Bit pattern Contribution =19.625 Radix-point

36
**Limitation of Fixed-Point Representation**

To represent large number of very small numbers we need a very long sequences of bits. This is because we have to give bits to both the integer part and the fraction part.

37
**Floating Point Representation**

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

38
**Floating point format M B E Sign mantissa or base exponent**

significand Sign Exponent Mantissa

39
**Floating Point Representation format**

Sign 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. Exponent Mantissa

40
IEEE 745 Standard The most important floating point representation is defined in IEEE Standard 754. It was developed to facilitate the portability from one processor to another. The IEEE Standard defines both a 32-bit and 64-bit format.

41
**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

42
Biased Exponent The exponent bit needs to represent both negative and positive numbers. Excess notation is used to represent negative and positive exponent. The exponent is represented with an excess of a fixed value b The value b is called to bias. And we say that the exponent is biased by the value b In IEEE single-precision format the the bias is We say the exponent is biased by 127

43
**Mantissa in IEEE single precision format**

The mantissa in this case has 23 bits. It should be normalised. For example: if the real mantissa is: then the normalised mantissa should be Because of this we do not need to store the 1. And as a result of this can use 23 to represent 24 bits. Which will achieve a great precision. This is what happens in IEEE 754 single precision.

44
**Mantissa in IEEE single precision format**

The mantissa in this case has 23 bits. It should be normalised. For example: if the real mantissa is: then the normalised mantissa should be Because of this we do not need to store the 1. And as a result of this can use 23 to represent 24 bits. Which will achieve a great precision. This is what happens in IEEE 754 single precision.

45
**Example (1) 5.7510 in IEEE single precision**

5.75 is a positive number then the sign bit is 0. 5.75 = * 20 = * 21 = * 22 The real mantissa is , then the normalised mantissa is The real exponent is 2 and the bias is 127, then the exponent is =12910 = The representation of 5.75 in IEE sing-precision is:

46
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 = 12810 It is biased by 127, hence the real exponent is 128 –127 = 1. The mantissa: It is normalised, hence the true mantissa is 1.01 = Finally, the number represented is: x 21 = -2.50 1

47
**Representation in IEEE 754 double precision format**

It uses 64 bits 1 bit sign 11 bit biased exponent 52 bit mantissa Sign Exponent Mantissa

48
**IEEE 754 double precision Biased = 1023**

11-bit exponent with an excess of 1023. For example: If the exponent is -1 we then add 1023 to it = 1022 We then find the binary representation of 1022 Which is The exponent field will now hold This means that we just represent -1 with an excess of 1023.

49
**Floating Point Representation format (summary)**

the sign bit represents the sign 0 for positive numbers 1 for negative numbers 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

50
**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.

51
**ASCII – example Symbol decimal Binary 7 55 00110111 8 56 00111000**

: ; < = > ? @ A B C

52
**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'

53
**Layered View of Representation**

Text string Information Data Sequence of characters Information Data Character Bit string

54
**Working With A Layered View of Representation**

Represent “SI” at the two layers shown on the previous slide. Representation schemes: Top layer - Character string to character sequence: Write each letter separately, enclosed in quotes. End string with ‘\0’. Bottom layer - Character to bit-string: Represent a character using the binary equivalent according to the ASCII table provided. NEED TO PROVIDE PRINTED ASCII TABLES

55
Solution SI ‘S’ ‘I’ ‘\0’ The colors are intended to help you read it; computers don’t care that all the bits run together.

56
exercise Use the ASCII table to write the ASCII code for the following: CIS110 6=2*3

57
**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.

58
**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?)

59
**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.

60
**Example: 2-bit per pixel**

= (white) 1 (dark grey) (light grey) (black) 4=22 choices 00 (off, off)=white 01 (off, on)=light grey 10 (on, off)=dark grey 11 (on, on)=black

61
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.

62
Bitmap Images Each individual pixel (pi(x)cture element) in a graphic stored as a binary number Pixel: A small area with associated coordinate location Example: each point below is represented by a 4-bit code corresponding to 1 of 16 shades of gray

63
**Representing Sound Graphically**

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

64
**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.

65
**Digitizing Sound Capture amplitude at these points**

Lose all variation between data points Zoomed Low Frequency Signal

66
**Summary Integer representation Fraction 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

67
Exercise Represent +0.8 in the following floating-point representation: 1-bit sign 4-bit exponent 6-bit normalised mantissa (significand). Convert the value represented back to decimal. Calculate the relative error of the representation.

Similar presentations

Presentation is loading. Please wait....

OK

Chapter 5 Data representation.

Chapter 5 Data representation.

© 2019 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google