# Representation of Numbers - NYU Representations Example: Numbers 145 CVL 10010001 91

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 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 2 8 16 Decimal Binary

Octal Hexadecimal What makes a good representations? Meet certain constraints on the symbols Intuitive interpretation Can express everything you need !! Support for frequent operations Efficiency

Space 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) Computer Representation Computer representation: Symbols: 0,1 Words = sequence of k symbols (bits) 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 Unsigned Integer Representation 145=1*102 + 4*101 + 5*100 10010001ui Decimal 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 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 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 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! Ones 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 11110 1 0 0 1 (-6) + 0 1 1 1 (+7) 0 0 0 0 (0) Does not work!

Twos 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 11100 1 0 1 0 (-6) + 0 1 1 1 (+7) 0 0 0 1 (+1) Twos compliment is useful for representing signed integers 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 twos complement Negation in twos 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