+ All Categories
Home > Documents > Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

Date post: 05-Jan-2016
Category:
Upload: noreen-casey
View: 218 times
Download: 0 times
Share this document with a friend
Popular Tags:
33
Tasanawan Soonklang Tasanawan Soonklang Department of Computing, Faculty of Science Department of Computing, Faculty of Science Data Data Representation Representation
Transcript
Page 1: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

Tasanawan SoonklangTasanawan SoonklangDepartment of Computing, Faculty of ScienceDepartment of Computing, Faculty of Science

Data RepresentationData Representation

Page 2: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

IntroductionIntroduction

Switching circuit : On, Off Number representation

Number system Number conversion

Integer Arithmetic Addition Subtraction Negation

Page 3: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

IntroductionIntroduction

Signed integer representation Sign magnitude Ones complement Twos complement

Character representation ASCII EBCDIC Unicode

Page 4: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

Number representation

Number system

N = bnbn-1bn-2…b2b1b0.b-1 b-2…b-m

r number (base-r) : 0,1,2,…,r-1 Binary (base2) : 0,1 Octal (base8) : 0,1,2,3,4,5,6,7 Decimal (base10) : 0,1,2,3,4,5,6,7,8,9 Hexadecimal (base16) : 0,1,2,3,4,5,6,7,8,9,

A,B,C,D,E,F

Page 5: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

Number conversionNumber conversion

Integer part

N = bn2n + bn-12n-1

+ … + b12 + b01

(123)10 = (1*102) + (2*101) + (3*100)

Position bn bn-1 … b2 b1 b0

Base2

Base8

Base10

Base16

2n

8n

10n

16n

2n-1

8n-1

10n-1

16n-1

22

82

102

162

21

81

101

161

20

80

100

160

Page 6: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

Number conversionNumber conversion

Base-r to decimal (11011)2 = 1*24 + 1*23 + 0*22 + 1*21 + 1*20

= 1*16 + 1*8 + 0*4 + 1*2 + 1*1

= 16 + 8 + 0 + 2 + 1

= 27 (1276)8 = 1*83 + 2*82 + 7*81 + 6*80

= 512 + 128 + 56 + 6

(2EA7)16 = 2*163 + A*162 + E*161 + 7*160

= 2*4096 + 10*256 + 14*16 + 7

Page 7: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

Number conversionNumber conversion

Decimal to base-r

(702)10 = (1276)8

8 ) 702 8 ) 87 6 8 ) 10 7 8 ) 1 2

0 1

(1632)10 = (660)16

16 ) 702 16 ) 87 0 16 ) 10 6 0 6

(19)10 = (10011)2

2 ) 19 mod 2 ) 9 1 2 ) 4 1 2 ) 2 0 2 ) 1 0 0 1

Page 8: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

Number conversionNumber conversion

fraction part

N = b-12-1 + b-22-2

+…+ b-(m-1)2-(m-1) + b-m2-m

position B-1 b-2 B-3 … B-(m-1) bm

Base2

Base8

Base10

Base16

2-1

8-1

10-1

16-1

2-2

8-2

10-2

16-2

2-3

8-3

10-3

16-3

2-(m-1)

8-(m-1)

10-(m-1)

16-(m-1)

2-m

8-m

10-m

16-m

Page 9: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

Number conversionNumber conversion

Base-r to decimal (.011)2 = 0*2-1 + 1*2-2 + 1*2-3

= 0 + 1/4 + 1/8

= 0 + 0.25 + 0.125 (.1142)8 = 1*8-1 + 1*8-2 + 4*8-3 + 2*8-4

= 1/8 + 1/64 + 4/512 + 2/4098

(.1A)16 = 1*16-1 + A*16-2

= 1/16 + 10/256

Page 10: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

Number conversionNumber conversion

Decimal to base-r

(.375)10 = (.011)2

.375 * 2 0 .750 *

2 1 .500 *

2 1 .000 *

Page 11: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

Integer arithmeticInteger arithmetic

Additiona b a+b carry1 1 0 1

1 0 1 0

0 1 1 0

0 0 0 0

Subtractiona b a-b carry1 1 0 0

1 0 1 0

0 1 1 1

0 0 0 0

1 1 1 1 0 0 + 1 1 0 0 1 1 1 0 1 0 1

1 1 0 1 0 1 - 1 0 0 1 1 0 0 0 1 0

Page 12: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

Integer arithmeticInteger arithmetic

Bitwise complementTake the Boolean complement of each bitThat is, set each 1 to 0 and each 0 to 1

NegationAdd 1 to the result

Twos complement operationTwo-step process Bitwise + negation

1 1 1 0 0 bitwise 0 0 0 1 1 + 1

0 0 1 0 0

Page 13: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

Signed integer representationSigned integer representation

Sign magnitude Ones complement Twos complement

Page 14: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

Sign magnitudeSign magnitude

Assign the high-order (leftmost) bit to the sign bit0 -> positive (+)1 -> negative (-)

The remaining (m-1) bits represent the magnitude of the number

Adv : familiarity Problem : positive & negative zero

Page 15: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

Sign magnitudeSign magnitude

8 bits : 1 sign bit, 7 magnitudebase10 base2 - 127 1111 1111

- 126 1111 1110

- 1 1000 0001

- 0 1000 0000

+ 0 0000 0000

+ 1 0000 0001

+ 126 0111 1110

+ 127 0111 1111

28 = 256 numbers - 0 1000 0000+ 0 0000 0000

Page 16: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

Ones complementOnes complement

Similar to sign magnitude Assign the high-order bit to the sign bit

0 -> positive (+)1 -> negative (-)

Take the bitwise complement of the remaining bits to represent the magnitude

Problem : positive & negative zero

Page 17: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

Ones complementOnes complement

8 bits : 1 sign bit, 7 magnitudebase10 base2 - 127 1000 0000

- 126 1000 0001

- 1 1111 1110

- 0 1000 0000

+ 0 0000 0000

+ 1 0000 0001

+ 126 0111 1110

+ 127 0111 1111

28 = 256 numbers - 0 1000 0000+ 0 0000 0000

Page 18: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

Twos complementTwos complement

Similar to ones complement Assign the high-order bit to the sign bit

0 -> positive (+)1 -> negative (-)

Take the twos complement operation of the remaining bits to represent the magnitude

Solution for positive & negative zero

Page 19: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

Twos complementTwos complement

8 bits : 1 sign bit, 7 magnitudebase10 base2 - 128 1000 0000

- 127 1000 0001

- 1 1111 1111

0 0000 0000

+ 1 0000 0001

+ 126 0111 1110

+ 127 0111 1111

0 0000 0000

0 = 0 0 0 0 bitwise 1 1 1 1

+ 1 1 0 0 0 0

- 0 = 0 ignore overflow

-8 = 1 0 0 0bitwise 0 1 1 1

+ 1 1 0 0 0

-(-8) = -8 monitor sign bit

Page 20: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

Addition & SubtractionAddition & Subtraction

Normal binary addition Monitor sign for overflow Overflow : the result is larger than can

be held in the word size Take twos compliment of subtrahend

and add to minuend A – B = A + (-B)

Page 21: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

Twos complementTwos complement

8 bits : 1 sign bit, 7 magnitude

The negative of the negative of that number is itself.

+18 = 0 0 0 1 0 0 1 0 bitwise = 1 1 1 0 1 1 0 1 + 1

1 1 1 0 1 1 1 0 = -18

-18 = 1 1 1 0 1 1 1 0bitwise = 1 1 1 0 1 1 0 1 - 1

0 0 0 1 0 0 1 0 = +18

Page 22: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

Twos complementTwos complement

Page 23: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

Twos complementTwos complement

Page 24: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.
Page 25: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

CharacterCharacter representationrepresentation

BCD – Binary code decimal EBCDIC – Extended binary code

decimal interchange code ASCII – American standard code for

information interchange Unicode

Page 26: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

BCDBCD

Binary system 6 bits for representing 1 character 26 = 64 codes 2 parts : Zone Bit (first 2 bits) and

Numeric Bit (last 4 bits)

Page 27: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

EBCDICEBCDIC

Binary system 8 bits for representing 1 character 28 = 256 codes 2 parts : Zone Bit (first 4 bits) and

Numeric Bit (last 4 bits) Developed by IBM

Page 28: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

EBCDICEBCDIC

Character Zone Digit

A,B,C,…,I 1100 0001-1001

J,K,L,…,R 1101 0001-1001

S,T,U,…,Z 1110 0001-1001

0,1,2,…,9 1111 0000-1001

a,b,c,…,i 1000 0001-1001

j,k,l,…,r 1001 0001-1001

s,t,u,…,z 1010 0001-1001

blank,$,.,<,>,(,+ 1011 0001-1001

&,!,*,),; 0100 0001-1001

-,/,’,_,? 0101 0001-1001

:,#,@,=,” 0111 0001-1001

Page 29: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

ASCIIASCII

8 bits for representing 1 character 28 = 256 codes 3 parts consist of

0-32 : control character32-127 (lower ASCII): English alphabets,

numbers, symbols128-256 (higher ASCII) : other language

alphabets (e.g. Thai)

Developed by ANSI (American national standard institute)

Page 30: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

ASCIIASCII

Lower ASCII Higher ASCII

Page 31: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

UnicodeUnicode

16 bits for representing 1 character 216 = 65,536 codes Enough for

alphabets in other language such as Chinese, Japanese

special symbols such as mathematic symbols

Widely use in many operating systems, applications and programming languages

Developed by Unicode consortium

Page 32: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

UnicodeUnicode

16 bits for representing 1 character 216 = 65,536 codes Enough for

alphabets in other language such as Chinese, Japanese

special symbols such as mathematic symbols

Widely use in many operating systems, applications and programming languages

Developed by Unicode consortium

Page 33: Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation.

UnitUnit

Name Abbr. Size Byte

Kilo K 210 1,024

Mega M 220 1,048,576

Giga G 230 1,073,741,824

Tera T 240 1,099,511,627,776

Peta P 250 1,125,899,906,842,624

Exa E 260 1,152,921,504,606,846,976

Zetta Z 270 1,180,591,620,717,411,303,424


Recommended