Data Representation - PowerPoint PPT Presentation

1 / 38
About This Presentation
Title:

Data Representation

Description:

Data Representation Dr. Ahmed El-Bialy Dr. Sahar Fawzy Other Binary Codes Binary Coded Decimal Gray Code Error Detection Codes Parity Codes Odd / even Generator ... – PowerPoint PPT presentation

Number of Views:650
Avg rating:3.0/5.0
Slides: 39
Provided by: AhmedE7
Category:

less

Transcript and Presenter's Notes

Title: Data Representation


1
Data Representation
  • Dr. Ahmed El-Bialy
  • Dr. Sahar Fawzy

2
Data Representation
  • To process data by brain, it must be converted to
    an appropriate internal format.
  • To process data by Computers, it must be
    converted to an appropriate internal formats
  • So how various types of data are stored
    internally in hardware ?

3
Data
  • Data are defined by
  • Set of Values
  • Set of operations on these values.

Text Characters Concatenation String Comparison
Numeric Numbers Vectors-Matrices Add- Sub- Multi

Instructions Machine Operations
4
Numeric Data
Real
Integers
Floating Point
Fixed Point
Unsigned
Signed
Decimal
Signed bit
Binary
1s Comp
Octal
2s Comp
Hexadecimal
5
Concept of Number System
Unsigned Integers
  • The Decimal (1346)10 (base 10) is
  • 1 x 1000 1000 1 x 103
  • 3 x 100 300 3 x 102
  • 4 x 10 40 4 x 101
  • 6 x 1 6 6 x 100 1346
  • The number (1011)2 (base 2) is
  • 1 x 8 8 1 x 23
  • 0 x 4 0 0 x 22
  • 1 x 2 2 1 x 21
  • 1 x 1 1 1 x 20 (13)10

6
Data Conversions
  • The radix (base) r
  • To convert from any type to decimal you multiply
    each digit by the base-power number
  • e.g. Octal (r8) (163)8

3x80
6x81
1x82
(115)10
7
Data Conversions
  • e.g. To convert from Binary to decimal you
    multiply each digit by the base-power (r2)
    (110110)2

0x20
1x21
1x22
0x23
1x24
1x25
(54)10
8
Data Conversions
  • e.g. To convert from Hex to decimal you multiply
    each digit by the base-power (r16) (C13FA2)16

2x160
Ax161
Fx162
3x163
1x164
Cx165
(12664738)10
9
From any System to Decimal
Binary
x 2n
Hexadecimal
Octal
x 8n
x 16n
Decimal
10
Conversion of Decimal to Binary
  • Repeat dividing of the decimal number by 2 and
    keep the remainder until you get a 0 quotient
  • e.g. Convert (125)10 to binary
  • 2 125
  • 2 62 1
  • 2 31 0
  • 2 15 1
  • 2 7 1
  • 2 3 1
  • 2 1 1
  • 0 1
  • ?(125)10 (1111101)2

11
Conversion of Decimal to Octal
  • Repeat dividing of the decimal number by 8 and
    keep the remainder until you get a 0 quotient
  • e.g. Convert (125)10 to Octal
  • 8 125
  • 8 15 5
  • 8 1 7
  • 0 1
  • ? (125)10 (175)8

12
Conversion of Decimal to Hex
  • Repeat dividing of the decimal number by 16 and
    keep the remainder until you get a 0 quotient
  • e.g. Convert (73462)10 to binary
  • 16 73462
  • 16 4591 6
  • 16 286 15 ? F
  • 16 17 14 ? E
  • 16 1 1
  • 0 1
  • -gt (73462)10 (11EF6)16

13
Conversion
Binary
2
x 2n
Hexadecimal
Octal
16
8
x 8n
x 16n
Decimal
14
Concept of Number System
  • Dec Bin Octal Hex
  • 0 0 0 0
  • 1 1 1 1
  • 2 10 2 2
  • 3 11 3 3
  • 4 100 4 4
  • 5 101 5 5
  • 6 110 6 6
  • 7 111 7 7
  • 8 1000 10 8
  • 9 1001 11 9
  • 10 1010 12 A
  • 11 1011 13 B
  • 12 1100 14 C
  • 13 1101 15 D
  • 14 1110 16 E
  • 15 1111 17 F

Dec Bin Octal Hex
16 10000 20 10 17 10001 21 11 18 10010 22 12 19
10011 23 13 20 10100 24 14 21 10101 25 15 22 1
0110 26 16 23 10111 27 17 24 11000 30 18 25 110
01 31 19 26 11010 32 1A 27 11011 33 1B 28 11100
34 1C 29 11101 35 1D 30 11110 36 1E 31 11111 3
7 1F
15
Conversion from Binary to Octal
  • Conversion between octal and binary is trivial.
    Since 23 8, every 3 binary digits converts to 1
    octal digit
  • The conversion is
  • Binary Octal
  • 000 0
  • 001 1
  • 010 2
  • 011 3
  • 100 4
  • 101 5
  • 110 6
  • 111 7

16
Conversion from Binary to Octal
  • Starting at the RIGHT, block the binary number
    into groups of 3 bits
  • e.g. (11011101101110)2
  • (011011101101110)2

  • (33556)8

17
Conversion from Octal to Binary
  • Conversion from octal to binary is even easier.
  • e.g. Convert (60125)8 to binary
  • 110000001010101
  • Then remove the dividing bars (60125)8
    (110000001010101)2

18
Conversion from Binary to Hex
  • Starting at the RIGHT, block the binary number
    into groups of 4 bits
  • e.g. (11011101101110)2
  • (0011011101101110)2

  • (376E)16

19
Conversion from Hex to Binary
  • Conversion from Hex to binary is easy.
  • e.g. Convert (3F56E)16 to binary
  • 00111111010101101110
  • Then remove the dividing bars
  • (3F56E)16 (111111010101101110) 2

20
Representing Signed Integers
  • The number system we studied represent positive
    numbers
  • In decimal, we have positive and negative
    numbers.
  • We should also take into consideration that the
    number of bits in a binary number is fixed by the
    hardware design (the machine's word length).

21
Representing Signed Integers
  • There are actually three possible schemes for
    representing signed numbers.
  • All agree on using the leftmost bit in the number
    to encode the sign
  • with 0 encoding
  • and 1 encoding -.
  • 1. Sign magnitude
  • 2. One's complement
  • 3. Two's complement

22
Sign-Magnitude
  • The simplest way to represent negative numbers is
    called sign-magnitude.
  • It is based on the method we use with decimal
    numbers
  • To represent a positive number in (say) 8 bits,
    represent its magnitude as seven bits and prefix
    a 0.
  • To represent a negative number in (say) 8 bits,
    represent its magnitude as seven bits and prefix
    a 1.
  • Example 65 ? 01000001
  • Example - 65 ? 11000001

23
1's complement
  • a better method is called 1's complement. In 1's
    complement, we proceed as follows
  • To represent a positive number in (say) 8 bits,
    represent it as an unsigned number using seven
    bits and prefix a 0.
  • To represent a negative number in 8 bits,
    represent its absolute value as above, then
    invert all the bits (which results in a left most
    bit of 1)
  • Example 65 ? 01000001
  • 1s complement - 65 ? 10111110

24
Two's complement
  • In 2s complement, add 1 to the 1s complement in
    case of a negative number
  • Example 65 ? 01000001
  • 1s complement - 65 ? 10111110
  • 2s complement - 65 ? 10111111

25
Addition in Binary
  • Example
  • 01011010 90
  • 01101100 108
  • ----------- ----
  • 11000110 198
  • Example
  • 00111001 57
  • 01011010 90
  • --------
  • 10010011 147

26
Subtraction in Binary2Complement
  • Examples
  • 00001000 8
  • 11111111 -1
  • -------- --
  • 00000111 7
  • Examples
  • 11111110 -2
  • 11111110 -2
  • -------- --
  • 11111100 -4
  • Examples
  • 11000001 -63
  • 01000000 64
  • -------- --
  • 00000001 1

1
carry out of sign position discarded
27
Real Numbers
  • Fixed point 234.567
  • 11234.56
  • 0.00034567
  • Floating point 2.34567 102
  • 1.123456 104
  • 3.4567 10-4

28
Real Numbers (2)
  • A real number is stored internally as a mantissa
    times a power of some radix
  • m r e
  • r 2 ( for binary)
  • m ? mantissa

29
Conversion of Fraction Decimal to Binary
  • Repeat multiplying of the decimal number by 2 and
    keep the units
  • e.g. Convert (.40625 )10 to binary
  • 0.40625 x 2 0.8125 units 0
  • 0.8125 x 2 1.625 units 1
  • 0.625 x 2 1.25 unit2 1
  • 0.25 x 2 0.5 unit2 0
  • 0.5 x 2 1.0 unit2 1
  • 0.0
  • (0.40625) 10 (0.01101) 2

30
IEEE Format
  • IEEE has developed a floating point standard
    (Standard 754)
  • The standard provides two different formats for
    single and double precision numbers.
  • We will consider the single precision
    representation as an example.

0
31
30
23
22
exp
mantissa
S
31
IEEE Format
  • s sign of mantissa 0 , 1 -
  • exp exponent as power of 2, stored in excess
    127 form - i.e. value stored is 127 true value.
  • ex true exponent 0 stored exponent 127
  • ex true exponent 127 stored exponent 254
  • ex true exponent -126 stored exponent 1

0
fraction
31
30
23
22
exp
mantissa
S
32
IEEE Format
  • The significand (magnitude of mantissa) is
    normalized to lie in the range 1.0 lt m lt 2.0.
    This implies that the leftmost bit is always 1,
    but need not be stored.
  • The 23 bits allocated are used to store the bits
    to the right of the binary point.
  • The missing leftmost bit 1 is inserted to the
    left of the binary point by the hardware when
    doing arithmetic. (This is called hidden-bit
    normalization, and is why this field is labeled
    "fraction".)

33
IEEE Format
  • e.g.
  • (-5.375) 10 ? (-101.011 ) 2 ?(-1.01011 x 22) 2
  • Sign bit 1 (negative)
  • exp 2 127 129 (10000001) 2
  • Significand 1.01011
  • Fraction 01011
  • IEEE format
  • 1 10000001 01011000000000000000000

34
Other Binary Codes
  • Binary Coded Decimal
  • Gray Code

35
Error Detection Codes
  • Parity Codes
  • Odd / even
  • Generator
  • Checker

36
Text
  • Computers deals only with numbers
  • Therefore, text is coded into numbers.
  • There are a variety of character codes in use on
    various systems, all of which begin by mapping
    the character set to a set of small unsigned
    integers, which are then in turn stored in binary
    form.

37
Text
  • ASCII (American Standard Code for Information
    Interchange) is the most widely used today.

38
Thank yousee you in theLogic Circuit and
Boolean Algebra
Write a Comment
User Comments (0)
About PowerShow.com