Download presentation
Presentation is loading. Please wait.
Published byNoreen Casey Modified over 9 years ago
1
Tasanawan Soonklang Department of Computing, Faculty of Science Data Representation
2
Introduction Switching circuit : On, Off Number representation Number system Number conversion Integer Arithmetic Addition Subtraction Negation
3
Introduction Signed integer representation Sign magnitude Ones complement Twos complement Character representation ASCII EBCDIC Unicode
4
Number representation Number system N = b n b n-1 b n-2 …b 2 b 1 b 0.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
5
Number conversion Integer part N = b n 2 n + b n-1 2 n-1 + … + b 1 2 + b 0 1 (123) 10 = (1*10 2 ) + (2*10 1 ) + (3*10 0 ) Position bnbn b n-1 … b2b2 b1b1 b0b0 Base2 Base8 Base10 Base16 2 n 8 n 10 n 16 n 2 n-1 8 n-1 10 n- 1 16 n- 1 …………………………2 8 2 10 2 16 2 2 1 8 1 10 1 16 1 2 0 8 0 10 0 16 0
6
Number conversion Base-r to decimal (11011) 2 = 1*2 4 + 1*2 3 + 0*2 2 + 1*2 1 + 1*2 0 = 1*16 + 1*8 + 0*4 + 1*2 + 1*1 = 16 + 8 + 0 + 2 + 1 = 27 (1276) 8 = 1*8 3 + 2*8 2 + 7*8 1 + 6*8 0 = 512 + 128 + 56 + 6 (2EA7) 16 = 2*16 3 + A*16 2 + E*16 1 + 7*16 0 = 2*4096 + 10*256 + 14*16 + 7
7
Number 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
8
Number conversion fraction part N = b -1 2 -1 + b -2 2 -2 +…+ b -(m-1) 2 -(m-1) + b -m 2 - m position B -1 b -2 B -3 … B -(m-1) bmbm 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
9
Number 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
10
Number conversion Decimal to base-r (.375) 10 = (.011) 2.375 * 2 0.750 * 2 1.500 * 2 1.000 *
11
Integer arithmetic Addition aba+b carry 11 0 1 10 1 0 01 1 0 00 0 0 Subtraction aba-b carry 11 0 0 10 1 0 01 1 1 00 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
12
Integer arithmetic Bitwise complement Take the Boolean complement of each bit That is, set each 1 to 0 and each 0 to 1 Negation Add 1 to the result Twos complement operation Two-step process Bitwise + negation 1 1 1 0 0 bitwise 0 0 0 1 1 + 1 0 0 1 0 0
13
Signed integer representation Sign magnitude Ones complement Twos complement
14
Sign magnitude Assign the high-order (leftmost) bit to the sign bit 0 -> positive (+) 1 -> negative (-) The remaining (m-1) bits represent the magnitude of the number Adv : familiarity Problem : positive & negative zero
15
Sign magnitude 8 bits : 1 sign bit, 7 magnitude base10base2 - 1271111 1111 - 1261111 1110 - 11000 0001 - 01000 0000 + 00000 0000 + 10000 0001 + 1260111 1110 + 1270111 1111 2 8 = 256 numbers - 01000 0000 + 00000 0000
16
Ones 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
17
Ones complement 8 bits : 1 sign bit, 7 magnitude base10base2 - 1271000 0000 - 1261000 0001 - 11111 1110 - 01000 0000 + 00000 0000 + 10000 0001 + 1260111 1110 + 1270111 1111 2 8 = 256 numbers - 01000 0000 + 00000 0000
18
Twos 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
19
Twos complement 8 bits : 1 sign bit, 7 magnitude base10base2 - 1281000 0000 - 1271000 0001 - 11111 1111 00000 0000 + 10000 0001 + 1260111 1110 + 1270111 1111 00000 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 0 bitwise 0 1 1 1 + 1 1 0 0 0 -(-8) = -8 monitor sign bit
20
Addition & 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)
21
Twos 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 0 bitwise = 1 1 1 0 1 1 0 1 - 1 0 0 0 1 0 0 1 0 = +18
22
Twos complement
25
Character representation BCD – Binary code decimal EBCDIC – Extended binary code decimal interchange code ASCII – American standard code for information interchange Unicode
26
BCD Binary system 6 bits for representing 1 character 2 6 = 64 codes 2 parts : Zone Bit (first 2 bits) and Numeric Bit (last 4 bits)
27
EBCDIC Binary system 8 bits for representing 1 character 2 8 = 256 codes 2 parts : Zone Bit (first 4 bits) and Numeric Bit (last 4 bits) Developed by IBM
28
EBCDIC CharacterZoneDigit A,B,C,…,I11000001-1001 J,K,L,…,R11010001-1001 S,T,U,…,Z11100001-1001 0,1,2,…,911110000-1001 a,b,c,…,i10000001-1001 j,k,l,…,r10010001-1001 s,t,u,…,z10100001-1001 blank,$,.,,(,+10110001-1001 &,!,*,),;01000001-1001 -,/,’,_,?01010001-1001 :,#,@,=,”01110001-1001
29
ASCII 8 bits for representing 1 character 2 8 = 256 codes 3 parts consist of 0-32 : control character 32-127 (lower ASCII): English alphabets, numbers, symbols 128-256 (higher ASCII) : other language alphabets (e.g. Thai) Developed by ANSI (American national standard institute)
30
ASCII Lower ASCII Higher ASCII
31
Unicode 16 bits for representing 1 character 2 16 = 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
32
Unicode 16 bits for representing 1 character 2 16 = 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
33
Unit NameAbbr.SizeByte KiloK2 10 1,024 MegaM2 20 1,048,576 GigaG2 30 1,073,741,824 TeraT2 40 1,099,511,627,776 PetaP2 50 1,125,899,906,842,624 ExaE2 60 1,152,921,504,606,846,976 ZettaZ2 70 1,180,591,620,717,411,303,424
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.