CA Lecture 2: Data Representation I - PowerPoint PPT Presentation

1 / 39
About This Presentation
Title:

CA Lecture 2: Data Representation I

Description:

The base, or radix, of a number system defines the range of possible values that ... Base 8 (octal) and base 16 (hexadecimal) radix, are related to base 2 (binary) ... – PowerPoint PPT presentation

Number of Views:75
Avg rating:3.0/5.0
Slides: 40
Provided by: spa951
Category:

less

Transcript and Presenter's Notes

Title: CA Lecture 2: Data Representation I


1
CA Lecture 2 Data Representation (I)
  • Fixed Point Numbers
  • (Chapter 2 of textbook)

2
Data Representation
  • Computer operations may or may not be
    arithmetic.
  • Before being manipulated, all kind of
    information must be represented by patterns of
    1s and 0s.
  • Data representation is about how the
    information should be represented in a machine.

3
Data Representation
  • Different kinds of representations fixed point
    numbers, floating point numbers, and characters.
  • There are limits imposed on the accuracy and
    range of numeric calculations by the finite
    nature of the data representations.

4
Fixed Point Numbers
  • Fixed point is one method to store numbers in a
    computer system.
  • In such a system, each number has exactly the
    same number of digits, and the point is always
    in the same place/position.
  • In computer, the position of binary point is
    not stored anywhere when representing real
    numbers.
  • Usually, fixed point numbers are used to
    represent integers.

5
Range and Precision in Fixed Point Numbers
  • A fixed point representation can be
    characterized by the range of expressible numbers
    and the precision.
  • Range is the distance between the largest and
    smallest numbers.
  • Precision is the distance between two adjacent
    numbers on a number line.
  • Error is 1/2 of the difference between two
    adjoining numbers.

6
Range and Precision in Fixed Point Numbers Cont.
  • Using only two digits of precision for signed
    base 10 numbers, with the decimal point placed on
    the far right.
  • The range (interval between lowest and highest
    numbers) is -99, 99 and the precision
    (distance between successive numbers) is 1.
  • The maximum error, which is the difference
    between the value of a real number and the
    closest representable number, is 1/2 the
    precision. For this case, the error is 1/2 X 1
    0.5.

7
Range and Precision in Fixed Point Numbers Cont.
  • A fixed-point unsigned decimal example using 3
    digits and the decimal point placed 2 digits from
    the right. What is the range, precision and
    error?
  • Range is 0.00, 9.99
  • Precision is 0.01
  • Error is 0.005

8
Range and Precision in Fixed Point Numbers Cont.
  • A fixed-point unsigned decimal example using 3
    digits and the decimal point placed on the far
    right. What is the range, precision and error?
  • Range is 000, 999
  • Precision is 1.0
  • Error is 0.5

9
Range and Precision in Fixed Point Numbers Cont.
  • A fixed-point unsigned decimal example using 3
    digits and the decimal point placed on the far
    left. What is the range, precision and error?
  • Range is .000,.999
  • Precision is .001
  • Error is .0005

10
Range and Precision in Fixed Point Numbers Cont.
  • Trade off between range and precision.
  • Range and precision are finite in the
    implementation of the architecture but are
    infinite in the real world.
  • Overflow will occur when a number is outside
    the range of the number system.

11
Radix Number Systems
  • The base, or radix, of a number system defines
    the range of possible values that a digit may
    have.
  • Weighted position code is the general form for
    determining the decimal value of a number in a
    base k fixed point number system.

12
Radix Number Systems Cont.
  • Weighted position code of k base number system

13
Convert base 2 to base 10
  • What is (1001)2 in base 10?
  • Answer 1 x 23 0 x 22 0 x 21 1 x 20
  • 8 1 910

14
Radix Number Systems Cont.
  • Polynomial method is a way to convert a number
    from an arbitrary base into a base 10 number.
  • The bit that carries the most weight is called
    the most significant bit (MSB), and the bit that
    carries the least weight is called the least
    significant bit (LSB).

15
Radix Number Systems Cont.
  • Base 8 (octal) and base 16 (hexadecimal) radix,
    are related to base 2 (binary).
  • Every 3 binary digits make up 1 octal digit
  • (010110)2 (010)2(110)2 (2)8(6)8 (26)8
  • Every 4 binary digits make up 1 hexadecimal
    digit
  • (10110110)2 (1011)2(0110)2 (B)16(6)16
    (B6)16

16
Conversion from base 10 to any base
  • Converting the integer part of a fixed point
    number the remainder method.
  • Converting the fractional part of a fixed point
    number the multiplication method.
  • Both methods utilize the general polynomial
    form of a binary number.

17
Base Conversion with the Remainder Method
18
Base Conversion with the Multiplication Method
19
Non-terminating Base 2 Fraction
  • We cant always convert a terminating base 10
    fraction into an equivalent terminating base 2
    fraction. Convert (0.2)10 to base 2

20
Simple Unsigned Binary Addition
  • Two binary numbers A and B are added from right
    to left, creating a sum and a carry in each bit
    position.
  • In each bit position, there are four cases if
    we ignore carry
  • 0 0, 0 1, 1 0, 1 1.

21
(No Transcript)
22
Simple Unsigned Binary Subtraction
  • What is (101)2 (010)2 ?
  • Answer is (011)2
  • What is (11001)2 (01110)2 ?
  • Answer is (01011)2

23
Signed Fixed Point Numbers
  • For an 8-bit representation, there are 28 256
    possible bit patterns. These bit patterns can
    represent both positive and negative numbers. We
    can assign half of the bit patterns to negative
    numbers and half of the bit patterns to positive
    numbers.
  • 4 different methods to represent signed fixed
    point numbers (we will cover) are
  • Signed Magnitude, Ones Complement
  • Twos Complement, Excess (Biased)

24
Signed Magnitude
  • Use the leftmost bit to represent the sign, 0
    for and 1 for .
  • The remaining bits contain the absolute
    magnitude.

25
Signed Magnitude
  • Two bit patterns are used to represent a single
    number zero (0 and 0).
  • Thus for 8-bit, signed magnitude can only
    represent 255 different numbers even though there
    are 256 bit patterns.

26
Ones Complement
  • Convert all of the 1s in the number to 0s, and
    all of the 0s to 1s.
  • In general, N-bit numbers are assigned to
    binary counter values in the obvious way as
    integers from 0 to 2N-1-1, and then the negative
    numbers are assigned in reverse order.
  • The term ones complement refers to the fact
    that negating a number in this format is
    accomplished by simply complementing the bit
    pattern (inverting each bit).

27
Ones Complement
28
Ones Complement
  • The leftmost bit is 0 for positive numbers.
  • The leftmost bit is 1 for negative numbers.
  • Two bit patterns are used to represent a single
    number zero (0 and 0).
  • Thus for 8-bit, ones complement can only
    represent 255 different numbers even though there
    are 256 bit patterns.

29
Twos Complement
  • The twos complement is formed in a way similar
    to forming the ones complement complement all
    of the bits in the number, then add 1 and discard
    any possible carry-out occurred at the MSB of the
    number.

30
Twos Complement cont.
  • Note that the leftmost bit is 0 for positive
    numbers, and is 1 for negative numbers.
  • There is an equal number of positive and negative
    numbers provided zero is considered to be a
    positive number, as the sign bit of zero is 0.
    The positive number starts at 0, but the negative
    numbers start at 1, thus the magnitude of the
    most negative number is one greater than the
    magnitude of the most positive number.
  • Thus there is no positive number to match 128
    for 8-bit representation of fixed point 2s
    complement.

31
Fixed Point Numbers Excess Representation
  • The leftmost bit is the sign (usually 1
    positive, 0 negative). Positive and negative
    representations of a number are obtained by
    adding a bias to the twos complement
    representation. This goes both ways, converting
    between positive and negative numbers. The effect
    is that numerically smaller numbers have smaller
    bit patterns, simplifying comparisons for
    floating point exponents.

32
Excess Representation
33
Excess Representation cont.
  • Another way to convert decimals to excess
    representation
  • add the excess (128)10 to the original number,
    and then create the unsigned binary version.
  • E.g. for (12)10 in excess 128 representation
  • Compute (128 12 140)10 and produce the
    unsigned binary pattern (10001100)2.
  • For (-12)10 in excess 128 representation
  • Compute (128 -12 116)10 and produce the
    unsigned binary pattern (01110100)2.

34
3-Bit Signed Integer Representations
35
Tutorial One Questions
  • 1. What is the decimal equivalent of the largest
    unsigned binary number that can be obtained with
  • a. 8 bits b. 32 bits c. n bits
  • 2. Convert the following unsigned binary numbers
    to decimal
  • a. 111010 b. 10101111.101 c. 110110110
  • 3. Convert the following decimal numbers to
    unsigned binary
  • a. 1950 b. 1011 c. 134 d. 2001

36
Tutorial One Questions Cont.
  • 4. Convert the following numbers with the
    indicated bases to decimal
  • a. (12101)3 b. (4231)5 c. (A89)12
  • 5. Convert the following decimal numbers to the
    indicated bases
  • a. 7562.45 to octal
  • c. 175.175 to binary
  • 6. Perform the following conversions
  • a. (764.7)8 to hexadecimal b. (F6D.C)16 to octal
  • c. (147.5)8 to base 4

37
Tutorial One Questions Cont.
  • 7. Represent the decimal values 26 and -123 as
    signed, 10-bit numbers in the following binary
    formats
  • a. Signed magnitude b. 1s complement
  • c. 2s complement
  • 8. What is the range of numbers for the
    2s-complement system, using n-bit
    representation?
  • 9. Compute the sum of 9 and 5 using binary
    numbers in 4-bit binary formats.

38
Tutorial One Questions Cont.
  • 10. How many bits are required to represent the
    following decimal numbers as unsigned binary
    integers?
  • 12 b. 147
  • 11. Convert the following decimal numbers to
    8-bit signed-magnitude representation
  • 23 b. 23 c. 48
  • 12. Convert the following decimal numbers to
    8-bit twos complement representation
  • 23 b. 23 c. 48

39
Tutorial One Questions Cont.
  • 13. Convert the following decimal numbers to
    3-bit excess 4 representation
  • 3 b. 3 c. 2
  • 14. Convert the following decimal numbers to
    8-bit excess 128 representation
  • 3 b. 3 c. 25
Write a Comment
User Comments (0)
About PowerShow.com