Download presentation
Presentation is loading. Please wait.
1
Representations Example: Numbers –145 –CVL –10010001 –91 –
2
Meaning of Number Representation Examples: –145 = 1*10 2 + 4*10 1 + 5*10 0 Decimal –CVL = 100 – 5 + 50 Roman –10010001=1*2 7 + 1*2 4 + 1*2 0 Binary –91 = 9*16 1 + 1*16 0 Hexadecimal – = 100 + 10+10+10+10+1+1+1+1+1 Egypt – = 2*60 + 10+10+5 Babylon – =7*20 + 5 Maya
3
Meaning of Numbers: Convention/Agreement –Any number consists of symbols –The value of a number is defined by a set of rules of how to interpret these symbols –Most systems have a base number 10 Decimal 2 Binary 8 Octal 16 Hexadecimal
4
What makes a good representations? Meet certain constraints on the symbols Intuitive interpretation Can express everything you need !! Support for frequent operations –Efficiency –Space
5
What do we want to represent: Data Types Set of objects of the same “kind” Defined by –a way of representing each object –a group of operations to perform on such objects Basic data types of computer –integers (unsigned and signed) –plain text characters –bit vectors –(floating point numbers)
6
Computer Representation Computer representation: –Symbols: 0,1 –Words = sequence of k symbols (bit’s) –8 bit =1 byte notation for an unknown k -bit word: –a k-1 a k-2 … a 1 a 0 –a k- 1 is called the most significant bit –a 0 is called the least significant bit k is always a power of 2: 16 or 32
7
Unsigned Integer Representation 145=1*10 2 + 4*10 1 + 5*10 0 Decimal 10010001 ui Binary =1*2 7 +0*2 6+ 0*2 5 +1*2 4 +0*2 3 +0*2 2 +0*2 1 +1*2 0 =1*128+0*64+0*32+1*16+0*8+0*4+0*2+1*0 =145 “Multiply and Add Algorithm”
9
How good is unsigned integer? Positive –Uses only 0 and 1 –Easy addition and conversion to decimal Negative –Limited size (2 k ) for k-bit word –No negative –Limited subtraction
10
Signed Integers need to represent both non-negative and negative integers need to be able to perform the following operations –addition (using the same rules as before) –negation –subtraction (trivial) three different representations will be considered –in all three representations words whose most significant bit –is 0 represent the same non-negative integer
11
Signed Magnitude Most significant bit determines whether the number is positive (a k-1 =0, as before ) or negative (a k-1 =1) 1 1 1 0 0k=4 1 1 1 0 (-6) + 0 1 1 1 (+7) 0 1 0 1 (+5) + –We now have negative numbers –Easy negation, only change first bit - –Addition does not work anymore Does not work!
12
One’s Compliment Positive number as before Negation is performed by inverting all bits Example: -6 = Inverse (6) = Inverse (0110) = 1001 “test” addition by adding 1001 with 0111 1 1 1 1 0 1 0 0 1 (-6) + 0 1 1 1 (+7) 0 0 0 0 (0) Does not work!
13
Two’s Compliment Positive as before Negation is performed by inverting all of the bits, and then adding 1 (binary) -6 = Inverse(6)+0001 = Inverse(0110)+0001 = 0110+0001=0111 “test” addition by adding 1010 with 0111 1 1 1 0 0 1 0 1 0 (-6) + 0 1 1 1 (+7) 0 0 0 1 (+1) Two’s compliment is useful for representing signed integers
14
Things you should be able to do Convert decimal number to binary and vice versa to all 4 forms of binary representation Addition in unsigned integer Addition and subtraction for two’s complement Negation in two’s complement Recognize the different subscripts: ui, sm, 1c,2c Understand why 2c is better than sm Know which representation (of the 4) is used for integer
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.