Computer Architecture, IFE CS and T&CS, 4thsem in Computer Systems Computer in of Integer Numbers Integer of Representation Representation Computer Architecture, IFE CS and T&CS, 4thsem Positional Numbering System Numbering Positional

Positional Systems: Positional numerals Roman ... but history – Systems Additive r –system base( ● ● ● A i a – digit position - digit - –valuenumber ( !!! numbers may !!!bases) have numbers infinitesome for ( representation e.g. 0,1 − 11,3125 dec −0,0(0011) = dec = −1101,0101 = ) bin A bin = ∑  i = ∞ − ∞ r i i a i Computer Architecture, IFE CS and T&CS, 4thsem Base System Base Base System ● ● ● may have different values digithave may different for positions ( constantallvalue digitfor positions ( may be other than natural number (negative, rational, complex, ...) (negative,rational,complex,number bethannatural may other factoradic r = (... 5!, 4!, 3!, 2!, 1!) = (... 120, 1) 6, 24, 2, (... = 5!,4!,3!,2!,1!) = (... factoradic r = angle:minute, (360,60,60) degree, second r minute, second= time:hour, (24,60,60) r , primoradic r = (... 11, 7, 5, 2,11, 5, 1) 3, 7, = (... r primoradic 54321 54321 54321 5×7 + 4×5 + 3×3 + 2×2 + 1×1 69 + 2×2= 1×1 + 4×5+ 3×3 + 5×7 -10 primoradic factoradic r r = = 5×5! + 4×4! + 3×3! + 2×2! + 1×1! = 719 1×1! 2×2! 3×3! = + + + + 4×4! 5×5! ( − radix 719 = 462810 = 69 = , , , binary dec dec ) dec fixed-radix mixed-radix ) ) Computer Architecture, IFE CS and T&CS, 4thsem Digits unique not is systems redundant in representation number radix than digits more using system non-redundant is r -radix system using standard digit set digit standard using system -radix ● ● ● ● ● ● ● hexadecimal decimal binary binary [0,1,2]: 1000 8 = binary[0,1,2]: 9 decimal0... → F decimal0... → binary → → → 0,1,2 or -1,0,1 or 0,1,2 0, 1 0,

0... 9 0... →

0... F 0... ♠, ♣, ♥, ♦ ♣,♥, ♠, dec and 0120and 8 = r dec is redundant is [0.. r -1] -1] Computer Architecture, IFE CS and T&CS, 4thsem Conventional Numbering System Taxonomy System Numbering Positionalfixed-radix systems with [ α =0 =0 Non-redundant minimal GSD Symmetric (BSD) signed-digit Binary r=2

signed-digit Non-redundant α≥ (even r) 1 (BSC) Binary saved-carry α = (SC) Saved-carry β r=2 α =0 =0

ρ=0 minimal GSD Asymmetric GSD Minimal

α≠β SB Non-binary −α ,−α β α =1(r OSD redundant Minimally α ρ= ] digit] set =r/2 +1 =r/2 +1 ≠ 1 2) signed-digit (GSD)signed-digit Generalized (OSD) signed-digit Ordinary GSD non-minimal Symmetric

α

ρ≥ 1 redundancy OSD redundant Maximally α =r-1 α

= redundant (UDR)redundant Unsigned-digit β β ρ≥ 2 GSD Non-minimal ρ=α+β+1-r α

=0 =0 GSD non-minimal Asymmetric

α≠β -borrow (SCB) Stored-carry-or α r=2 BSCB BSCB =1, =1, β =r Computer Architecture, IFE CS and T&CS, 4thsem Capacity numbers from arbitrary range [0 ... max]? ... [0 range arbitrary from numbers accommodate to needed are digits many How number: n-digit with system, (non-redundant) standard In e.g. for 50000numbers (representations) inbinary: the numberof uniquerepresentations is only numbers inrange [0 ... n ●

log log = binary: 8-bits, range 0...255, uniquerange0...255, valuesbinary: 8-bits, 256 2 2 floor 50000 49999+1 [  log = 15.61 → (ceil) → 16 digits16→ (ceil) (bits) 15.61 = → 16.61= r max → (floor) → 16 digits (bits) → (floor) →  ]  1 = r n -1]can be represented ceil r -radix numbering numbering -radix [ log r  r n max  1  ] Computer Architecture, IFE CS and T&CS, 4thsem Optimal radix Optimal Mathematical criterion: E(r) = r * n * r = E(r) criterion: Mathematical ? range[0...max] given a in numbers represent to radix) (i.e. system numbering best" "the is What non-redundant): standard, (for Criteria ● ● ● where simplealgorithms (?) convenientphysical realization and handling anddigits r) (small representation few n) (small short r is numbering system radix for n-digit number radixnumbering for is system (one of possibleout many (one criteria) Computer Architecture, IFE CS and T&CS, 4thsem Optimal radix Optimal E  r Looking for maximum of function: E(r) = r * n r * = E(r) of function: maximum for Looking  = andoffers physical better implementation possibilities. (accordingcriterion)Optimal E(r) to radixalmost 2isbut goodas 3, is r ∗ n = r ∗ log E E dE dr   r 3 2  max   = = ln 1.056  r  max optimal 1  = ,  r = E E ∗ 1  e   10 ln = ∗ 2   2.71 ln  ln max = ln   1.5 r 2 r     r −  1 1  = = 0 ln  max  1  ∗ ln r  r  Computer Architecture, IFE CS and T&CS, 4thsem Special Codes Special Gray code – non-positional binary code binary –non-positional code Gray converters, angle/positionconverters, etc.) sensors, applications: hazard-free digitalelectronics A/D (counters, onebit (cyclic code) codesfor first andlast represented values also differ in only values two codesofevery successive differin onlyone bit value 7 6 5 4 3 2 1 0 Gray 1 1 0 0 1 0 1 1 1 1 1 1 0 0 1 0 0 1 1 0 0 1 0 0 0 Computer Architecture, IFE CS and T&CS, 4thsem Special Codes Special BCD – Binary-Coded Decimal Binary-Coded – BCD applications: accommodatepositive numbers in ranage0..99 eachdecimal digit codedwith 4bits, one byte can digit 9 8 7 6 5 4 3 2 1 0 ● ● direct operationsdirect decimalon in numberscode binary – no communicationdigitalwith LEDdisplays 7-segment problemswithdecimal/binary/decimal conversions 1 1 0 0 1 1 0 0 0 0 1 1 1 0 1 1 0 0 1 0 1 0 1 0 0 0 0 1 1 0 0 1 0 0 0 0 1 0 0 0 0 BCD 5127 DEC = 0101000100100111= BCD Computer Architecture, IFE CS and T&CS, 4thsem Natural Binary Code (NBC) Code Binary Natural NBC cannot represent negative values negative represent cannot NBC features: NBC n-bit representationof non-negative values [0... 2 fixedradix-2 withtwo digits0 and 1([0,1] digitset) 4-bits: 64-bits: 32-bits: 16-bits: 8-bits: range 0 ... 2 range0... range 0 ... 2 range0... 2 range0... 2 range0... 2 range0... a n − 1 a n ... 64 32 16 8 4 a -1 -1 -1 -1 → 0 ... 18 44618 744 073 7090 551→ ... 615 -1 2949674 295 0→ ... -1 53565 0→ ... -1 1 → 0 ... 255 ... 0 → 15 ... 0 → a 0 = ∑ i n = − 0 1 2 i a i n -1] Computer Architecture, IFE CS and T&CS, 4thsem Arithmetic Overflow in NBC in Overflow Arithmetic Units for the purpose of correctness control of correctness purpose the for Units Arithmetical-Logical by stored always is Carry-bit ) (unsigned NBC in overflow arithmetic signals Carry-bit of range out operation of results Overflow: e.g.8-bit: 11111111 + 00000001= 1 00000000 Computer Architecture, IFE CS and T&CS, 4thsem Negative Numbers Coding Numbers Negative Complement coding (1's, 2's) (1's, coding Complement excess-N) (or coding Biased (S-M) coding Signed-magnitude (?) representation Intuitive (addition/subtraction) operations arithmetic Simple rep. positive of range on numbers negative Mapping Computer Architecture, IFE CS and T&CS, 4thsem Signed-Magnitude (S-M) Signed-Magnitude Binary n-digit S-M code: S-M n-digit Binary solution simplest and Oldest Disadvantages: Advantages: ● ● ● ● ● ● ● range of representation is symmetrical [ symmetrical rangeofrepresentationis positive)– negative,0(1 – numbersignthe the of represents significant most (MSB) bit doublerepresentationofzero complexarithmetical operations (addition/subtraction) !!! simplenegation range symmetrical intuitiverepresentation − − +0 49 49 0 − DEC DEC DEC DEC 2 n-1 = 00110001= = 10110001= = 10000000= 00000000= +1 , 2 , n-1 − 1 ] ZM ZM ZM ZM Computer Architecture, IFE CS and T&CS, 4thsem Signed-Magnitude (S-M) Signed-Magnitude − N −1 mapping onto NBC onto mapping

Increment 1100 1011 -4 1101 -3 -5 1010 1110 -2 -6 0 +P 0 +P 1001 1111 -1 -7 − 1000 0000 -0 +0 + 0111 0001 +7 +1 0110 0010 +6 +2 0101 0100 0011 +5 +4 +3 − represented values represented 0 −1−N

Increment Computer Architecture, IFE CS and T&CS, 4thsem Biased Coding (Excess-N) Coding Biased Disadvantages: Advantages: value bias a of addition requires Conversion N+P] [0, positive onto mapped is +P] [−N, Range ● ● ● ● quiteintuitive representation multiplication/divisiondifficultis addition/subtractionresultof correction requires linearmapping numbersiseasy– comparison oftwo − [ −4, +11 ] → [ 0, 15 ], bias = 4 = bias ], 150, [ → ] +11 −4, 1 → 3 → 1 Computer Architecture, IFE CS and T&CS, 4thsem -16 Biased Coding Biased 16 DEC DEC Binary n-digit Excess-N code: Excess-N n-digit Binary

total(similar tocomplement 2's negation) negation requiresnegation of all bits and addition of 1 tothe operation onMSB only bias correction(addition/subtraction)is N=2 easy for –(0 negative, 1 –positive) – opposite toS-M MSBtocorresponds signof the coded value amounts bias (N) to 2 rangeof representation [

→ → 16 -16 DEC DEC + bias = 16 = bias + + bias = -16 bias= + n-1 DEC DEC − + 128 + + 128 + 2 n-1 , , 2 n-1 DEC DEC − = 10010000 = 1] = 01110000= Excess128 Excess128 n-1 , , Computer Architecture, IFE CS and T&CS, 4thsem Biased Coding – Correction – Coding Biased a correction: a requires operations addition/subtraction of Result NBC as rules same the to according performed be can Addition/subtraction X XY + biasY y = + biasX x = + − Y → → x + biasx bias+ 2*bias+ bias + x y + y = x − y y − bias = x − 0*bias+ y → → X X Y+ − Y + − bias bias Computer Architecture, IFE CS and T&CS, 4thsem Biased Coding Biased − N −1 mapping onto NBC onto mapping Increment 1100 +4 1011 1101 +3 +5 1010 1110 +2 +6 1001 1111 − 0 +P +1 +7 N −1 + 1000 0000 0 -8 − 0111 0001 -1 -7 0110 0010 -2 -6 0101 0100 0011 -3 -4 -5 0 +P represented values represented

Increment Computer Architecture, IFE CS and T&CS, 4thsem Complement Coding Complement Disadvantages: Advantages: MN+P+1 = aconstant to complement as calculated is numbers negative of Representation NBC with identical are numbers Positive N+P] [0, onto mapped is +P] [−N, Range − x = M = x ● ● non-intuitive representation (but not for computers...:) non-intuitive for not representation(but simpleoperations – identical arithmetic asinNBC !!! − x − [ −4, +11 ] → [ 0, 15 ], M = 16 = M ], 150, [ → ] +11 −4, 1 → 15→ 1 Computer Architecture, IFE CS and T&CS, 4thsem Binary 2's Complement Coding (2C) Coding Complement 2's Binary Modulo-M arithmetics: Modulo-M Negation: positive) 0 – – negative, (1 number ofthe sign the to corresponds MSB 2 = M constant Complement [ ofrepresentation Range = bit_negation(x)= 1 + − x = 2 = x (drop (drop carry-out) ignoring from position bit last – carry (C Carry) (n-1) n − x = x − (2 n – 1) − x + 1 + x – − = 11...11) − 2 n-1 n ( , 2 radix-complement BIN n-1 − x + + 1 = − x − 1] ) Computer Architecture, IFE CS and T&CS, 4thsem 2's Complement Negation Complement 2's Negation of a number x: number a of Negation c) from c) weighted-positionformula (binary) b) from definition (allpositional) a) simple rule bit_negation(x) (binary): 1 + A U2 = − negativeweight 2 sign withsign n − 1 a n − 1  ∑ magnitude − i n inNBC x = = M x = − 0 2 2 i − a x i Computer Architecture, IFE CS and T&CS, 4thsem Arithmetic Overflow in 2C in Overflow Arithmetic (signed-arithmetic) 2C in overflow arithmetic signals V-bit control correctness of purpose the for Units Logical Arithmetical- by calculated always is (V) bit Overflow 2C in overflow arithmetic signal not does Carry-bit of range out operation of results Overflow: e.g. 8-bit:11111111 00000001+ = overflowif two operands havethe same sign, e.g. 8-bit:01111111 00000001+ 10000000= but differentthan – result simplecomparison ofMSB's (correct result, Carry is just result, Carry a side-effect) (correct 1 00000000 Computer Architecture, IFE CS and T&CS, 4thsem 2's Complement Coding Complement 2's − N −1 mapping onto NBC onto mapping Increment 1100 1011 -4 1101 -5 -3 1010 1110 -6 -2 0 +P 0 +P 1001 1111 -7 -1 − 1000 0000 -8 0 + 0111 0001 7 1 0110 0010 6 2 0101 0100 0011 5 4 3 − represented values represented N −1

Increment Computer Architecture, IFE CS and T&CS, 4thsem Binary 1's Complement Coding (1C) Coding Complement 1's Binary Modulo-M arithmetics Modulo-M Negation: zero of representation Double positive) 0 – – negative, (1 number ofthe sign the to corresponds MSB 2 = M constant Complementation [ ofrepresentation Range − x = 2 = x adding carry bit (C – Carry) adding positionbitfrom last (C – (n-1) carry Carry) to the n

− total (end-aroundcarry)

1 − x = 1 = 11...1 − x BIN − x = bit_negation(x)= x − −

2 n-1 +1

, 2 n − n-1 1 ( 1 − digit-complement 1 ] ) Computer Architecture, IFE CS and T&CS, 4thsem 1's Complement Coding (U1) Coding Complement 1's − N −1 mapping onto NBC onto mapping

Increment 1100 1011 -3 1101 -4 -2 1010 1110 -5 -1 0 +P 0 +P 1001 1111 -6 -0 − 1000 0000 -7 0 + 0111 0001 7 1 0110 0010 6 2 0101 0100 0011 5 4 3 − represented values represented N −10

Increment