Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Ethics of Computing MONT 113G, Spring 2012 Session 4 Binary Addition.

Similar presentations


Presentation on theme: "1 Ethics of Computing MONT 113G, Spring 2012 Session 4 Binary Addition."— Presentation transcript:

1 1 Ethics of Computing MONT 113G, Spring 2012 Session 4 Binary Addition

2 2 Signed Magnitude We want to represent both positive and negative integers. How? Method 1 (Signed Magnitude): Use leftmost bit to indicate the sign. 1 => negative number 0 => positive number Example: Assume an 8 bit integer, represent +3 and -3 +3 = ? +3 = 00000011 -3 = ? -3 = 10000011

3 3 One's Complement Method 2: One's Complement. 1st digit represents the sign (1 => negative) If the number is negative, take the positive representation and flip each bit (from 1 to 0 or from 0 to 1). Example: +3 = ? +3 = 00000011 -3 = ? -3 = 11111100

4 4 Two's Complement Method 3: Two's complement 1st digit represents the sign (1 => negative) If the number is negative, take the positive representation and flip each bit (from 1 to 0 or from 0 to 1) and add 1. Example: +3 = ? +3 = 00000011 -3 = ? -3 = 11111101

5 5 Binary Addition Addition: adding two positive numbers Add 14 and 11: 1400001110 +1100001011 2500011001(Check result) Subtraction: add a negative number to a positive number Subtract 11 from 14. 14 00001110 00001110 - 11- 00001011+11110101 3 00000011

6 6 When the numbers are too big What happens when we add 127 to 60, using 8 bit integers? 12701111111 +6000111100 18710111011 = -69 What is the largest number we can represent with n bits? 1 bit for the sign. Can represent 2 n-1 -1 as the largest number. With 8 bits, can represent 2 7 -1 = 127

7 7 Floating point representation Floating point (real) numbers use 32 bits: 1 sign bit 7 bits for exponent 24 bit fraction Recall scientific notation: 18,000 = 1.8 x 10 4 Example: 0 1000011 10101000... (rest zeros) Sign is zero => positive Exponent = + 3 (sign bit for exponent uses 1 for positive) Fraction =.10101 2 3 x.10101 = 101.01 = 1 x 4 + 0 x 2 + 1 x 1 + 0 x.5 + 1 x.25 = 5.25

8 8 Recall Digital Gates Other useful gates: OR Gate Inverter NOR Gate NAND Gate XOR (Exclusive OR) Gate s1 V s2 s1 (s1  s2) (s1 V s2) AND Gate (s1  s2)

9 9 Building a Half-Adder Design a circuit that, given 2 input digits will give the sum and carry digits produced by adding the two inputs. a 1 1 0 0 +b+1+0+1+0 cs10010100 a b c s Truth Table

10 10 The Half Adder Circuit c = a  b s = (a  b) V ( a  b)

11 11 Building a Full Adder a 1 1 1 1 0 0 0 0 b 1 1 0 0 1 1 0 0 +c+1+0+1+0+1+0+1+0 ed11101001 10010100 For the full adder, we must add three digits: The two from the numbers we are adding and the carry digit. a b c e d Truth Table

12 12 Half of the full adder

13 13 Universal Building Blocks One can build any logical circuit with the following gates: 2 input AND gate 2 input OR gate Inverter In fact, one can build any logical circuit with just 1 type of gate: 2 input NAND

14 14 Everything from NAND NOT a true z = a AND a b z = a  b true OR a b z = a V b true


Download ppt "1 Ethics of Computing MONT 113G, Spring 2012 Session 4 Binary Addition."

Similar presentations


Ads by Google