27
Data Representation Prepared by: Dr. Anju Sharma SMCA

Data Representation (1) (1)

Embed Size (px)

Citation preview

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 1/27

Data Representation

Prepared by:

Dr. Anju Sharma

SMCA

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 2/27

CONTENTS

Data Types

Complements

Fixed Point Representation

Floating Point Representation

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 3/27

Data Representation in Digital

System OR Data Types Numbers used in arithmetic computations

Letters of the alphabet used in data

processing (ASCII Code) Other symbols used for specific purpose

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 4/27

Number Systems

Base or R adix r system : uses distinctsymbols for r digi ts

Most common number system :Decimal,Binary, Octal, Hexadecimal

Positional-value(weight) System : r 2 r 1r 0.r -1

r -2 r -3

Multiply each digit by an integer power of r and then form the sum of all weighteddigits

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 5/27

Number Systems ± Decimal

Base 10

 ± Ten digits, 0-9

 ± Columns represent (from right to left) units, tens,

hundreds etc.

123

1v102 + 2v101 + 3v100

or

1 hundred, 2 tens and 3 units

Each position is a power of 10

3052 = 3 x 103

+ 0 x 102

+ 5 x 101

+ 2 x 100

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 6/27

Bases

The base of a number is often indicated by asubscript. E.g. (123)10 indicates the base-10number 123.

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 7/27

Binary

Base 2

 ± Two digits, 0 & 1

 ± Columns represent (from right to left) units,twos, fours, eights etc.

1111011

1v26 + 1v25 + 1v24 + 1v23 + 0v22 + 1v21 + 1v20

= 1v64 + 1v32 + 1v16 + 1v8 + 0v4 + 1v2 + 1v1

= 123

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 8/27

Decimal to Binary Conversion

123 z 2 = 61 remainder 1

61 z 2 = 30 remainder 130 z 2 = 15 remainder 015 z 2 = 7 remainder 17 z 2 = 3 remainder 1

3z

2 = 1 remainder 11 z 2 = 0 remainder 1

Least significant bit (rightmost)

Most significant bit (leftmost)

(123)10 = (1111011)2

Example Converting (123)10 into binary

Read the result upward to give an answer of 

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 9/27

Hexadecimal

Base 16

 ± Sixteen digits, 0-9 and A-F (ten to fifteen)

 ± Columns represent (from right to left) units,16s, 256s, 4096s etc.

7B

7v161 + 11v160 = 123

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 10/27

Decimal to Hex Conversion

123z

16 = 7 remainder 11 (or B)7 z 16 = 0 remainder 7

 Answer : (123)10 = (7B)16

Converting (123)10 into hex

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 11/27

Binary to Hex / Hex to Binary

Even very long numbers can be convertedeasily, treating each hex digit independently.

0111 1011

7 B

1011 1001 0110 1111 1010

B 9 6 F A

E.g.

Each group of four binary bits maps on to a single hexdigit.

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 12/27

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 13/27

COMPLEMENTS

 Adding to 1 to the r¶-1 complement 

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 14/27

Finding Two¶s Complement

Step 1: First complement all the bits

(that is find one¶s complement)

 ± Make all 1s as 0s and all 0s as 1s

Step 2:Then perform increment by 1

 ± Add 0001b

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 15/27

Two¶s Complement as -ve

Number  Two¶s complement is -ve number because

binary addition of a n-bit number with it¶s

complement gives nbit result with all bits = 0s

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 16/27

Highest Two¶s Complement format +

ve Number  A highest positive arithmetic number is

when at msb there is 0 and all

remaining bits are 1s

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 17/27

Lowest Two¶s Complement format

í

 ve Number  A lowest negative arithmetic number is

when at msb there is 1 and all

remaining bits are 0s

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 18/27

Arithmetic Numbers

Two¶s complement format arithmetic number 

Maximum 8-bit number = 0111 1111( +127)

Minimum 8-bit number = 1000 0000 (í

128)

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 19/27

Arithmetic Numbers

Two¶s complement format arithmetic

number 

Maximum 16-bit number  = 0111 1111 1111 1111( +32767)

Minimum 16-bit number 

= 1000 0000 0000 0000 ( í

32768)

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 20/27

EXAMPLE

Number +16392 0100 0000 0000 1000

One¶s complement 1011 1111 1111 0111

+ 0000 0000 0000 0001í163921011 1111 1111 1000

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 21/27

Binary subtraction A í B

Add A with two¶s complement of B to find

 A í B, provided we use two¶s

complementation for representation í ve

numbers

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 22/27

Example: Find 129 í 128

0000 0000 1000 0001 [= +129d]

1111 1111 1000 0000 [= í 128d]

0000 0000 0000 0001 [= + 1d]

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 23/27

SUMMARY

Two¶s complement is found by first

finding 1¶s complement and then adding

0001b.

Two¶s complement gives negative of a

given number 

Adding a number with it¶s two¶s

complement gives all bits = 0s

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 24/27

Binary Arithmetic - Addition

Binary long addition works just like

decimal long addition.

1 0 0 1 1 1

0 0 1 1 1 0

010

11

01

11

00

1

+

Carried digits

Result 

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 25/27

OVERFLOW

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 26/27

Floating Point Representation

8/8/2019 Data Representation (1) (1)

http://slidepdf.com/reader/full/data-representation-1-1 27/27

example

 ± 0.12 × 0.12 = 0.0144

would be expressed as

 ± (1.2 × 10í

1) × (1.2 × 10í

1) = (1.44 × 10í

2). In a fixed-point system with the decimal

point at the left, it would be

 ± 0.120 × 0.120 = 0.014.