1 / 14

Representations

Representations. Example: Numbers 145 CVL 10010001 91. 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

dayo
Download Presentation

Representations

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Representations • Example: Numbers • 145 • CVL • 10010001 • 91

  2. Meaning of Number Representation • Examples: • 145 = 1*102 + 4*101 + 5*100 Decimal • CVL = 100 – 5 + 50 Roman • 10010001=1*27 + 1*24 + 1*20 Binary • 91 = 9*161 + 1*160 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: • ak-1a k-2 … a1a0 • ak-1is called the most significant bit • a0 is called the least significant bit • k is always a power of 2: 16 or 32

  7. Unsigned Integer Representation • 145=1*102 + 4*101 + 5*100 Decimal • 10010001ui Binary =1*27 +0*26+0*25 +1*24 +0*23 +0*22 +0*21 +1*20 =1*128+0*64+0*32+1*16+0*8+0*4+0*2+1*0 =145 “Multiply and Add Algorithm”

  8. How good is unsigned integer? • Positive • Uses only 0 and 1 • Easy addition and conversion to decimal • Negative • Limited size (2k) for k-bit word • No negative • Limited subtraction

  9. 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

  10. Signed Magnitude • Most significant bit determines whether the number is positive (ak-1=0, as before ) or negative (ak-1=1) 1 1 1 0 0 k=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!

  11. 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!

  12. 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

  13. 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

More Related