Presentation is loading. Please wait.

Presentation is loading. Please wait.

Outline Binary Addition 2’s complement Binary Subtraction Half Adder

Similar presentations


Presentation on theme: "Outline Binary Addition 2’s complement Binary Subtraction Half Adder"— Presentation transcript:

0 Binary Arithmetic

1 Outline Binary Addition 2’s complement Binary Subtraction Half Adder Logisim

2 Binary Addition How to add two binary numbers? Single bit: + 0 + 1 1 1 + 0 1 + 1 10 carry bit

3 10 13 + 9 2 10 13 + 9 22 13 + 9 Binary Addition What is a carry bit?
Same idea as “carry the 1” in decimal arithmetic: 10 13 + 9 2 10 13 + 9 22 13 + 9

4 Binary Addition carry bit gets “carried over” to the next bit (to the left..) Just like decimal addition + 0 + 1 1 1 + 0 1 + 1 10 carry bit

5 Binary Addition Example #1

6 Binary Addition Example #1 carry bit

7 0100 0011 + 0000 1010 0100 1101 67 + 10 77 Binary Addition Example #1
You can always check your work by converting to decimal 67 + 10 77

8 Binary Addition Example #2

9 1001 1100 1100 0110 + 0100 1010 1 0001 0000 Binary Addition Example #2
9th bit!?!

10 1100 0110 + 0100 1010 1 0001 0000 Binary Addition Example #2
If we must store the answer in a single byte, 9th bit gets ignored… This is known as overflow

11 Shouldn’t the answer be 272?
Binary Addition Example #2 198 + 74 16 16 !?! Shouldn’t the answer be 272?

12 Binary Addition What’s the largest number that can be stored in 8-bits? ???

13 Binary Addition What’s the largest number that can be stored in 8-bits? 272 is greater than 255 272 cannot be represented using 8 bits Has this ever happened to you? 255

14 Outline Binary Addition 2’s complement Binary Subtraction Half Adder Logisim

15 8-bits can be used to represent numbers between 0 and 255
2’s Complement 8-bits can be used to represent numbers between 0 and 255 How do we represent negative numbers in binary? Drumroll…. 2’s complement!! Makes addition, subtraction, multiplication easier Most common way to represent signed numbers Signed: positive AND negative numbers And no, it’s not 2’s compliment “Hey 2, your hair looks nice today..”

16 In 2’s complement system, the leftmost bit indicates the sign
0 for positive 1 for negative When the leftmost bit is 0, the remaining bits are interpreted as before => 1 => 127

17 2’s Complement When the leftmost bit is 1, we do the following to obtain the signed decimal representation: Complement (invert) the binary digits (0 => 1; 1 => 0) Convert binary digits to decimal number Multiply by -1 Subtract 1

18 1100 0110 Invert bits: 0011 1001 Convert to decimal: 57
2’s Complement Example #1: What is the 2’s complement value of ? Invert bits: Convert to decimal: 57 Multiple by -1: -57 Subtract 1: -58

19 2’s Complement Example #2: What is the 2’s complement value of ? Your turn!

20 1001 1001 Invert bits: 0110 0110 Convert to decimal: 102
2’s Complement Example #2: What is the 2’s complement value of ? Invert bits: Convert to decimal: 102 Multiple by -1: -102 Subtract 1: -103

21 Decimal to 2’s complement If the number is positive:
leftmost bit is 0 remaining bits identical to unsigned binary number E.g., Represent the number 97 using 8-bits, 2’s complement 97 = = =

22 Decimal to 2’s complement If decimal number is negative:
add 1 multiply by -1 (to create positive number) create binary sequence invert bits

23 add 1: -97 + 1 = -96 multiply by -1: -96 × -1 = 96
2’s Complement Example #3: represent -97 using 8-bits, 2’s complement add 1: = -96 multiply by -1: -96 × -1 = 96 get binary: = invert bits: -97 =>

24 add 1: -123 + 1 = -122 multiply by -1: -122 × -1 = 122
2’s Complement Example #4: represent -123 using 8-bits, 2’s complement add 1: = -122 multiply by -1: × -1 = 122 get binary: = invert bits: -123 =>

25 Break Time!!!

26 Outline Binary Addition 2’s complement Binary Subtraction Half Adder Logisim

27 To subtract two binary numbers, X – Y,
Binary Subtraction To subtract two binary numbers, X – Y, Invert Y => Y’ Add 1 to Y’ Add X + Y’ We are basically taking the 2’s complement of Y (Y’) before adding it to X

28 0010 0001 - 0000 1010 invert Y 00001010 => 11110101 add 1 to Y’
Binary Subtraction Example #5: invert Y => add 1 to Y’ = add Y’ to X this 9th bit 1 gets ignored

29 Binary Subtraction It’s always good to verify your work… 33 - 10 23

30 Binary Subtraction Example #6

31 Binary Subtraction Example #6 invert Y => add 1 to Y’ = add Y’ to X

32 Binary Subtraction Verify… 25 - -30 55

33 Outline Binary Addition 2’s complement Binary Subtraction Half Adder Logisim

34 Can use logic gates to construct adder circuit
Half Adder Can use logic gates to construct adder circuit Circuit is capable of binary addition Half Adder has two inputs (A, B) and two outputs (S, C) S: sum C: carry A Half Adder S B C

35 Truth table for Half Adder
S : sum of A + B C : carry bit A B S C 1 Half Adder A B S C

36 Logic gate circuit for Half Adder?
A, B inputs S, C outputs A B S C 1

37 Logic gate circuit for Half Adder?
A, B inputs S, C outputs A B S C 1

38 How would you expand the Half Adder to create a:
2-bit adder? 4-bit adder? 8-bit adder? …? This will be part of your homework…

39 Outline Binary Addition 2’s complement Binary Subtraction Half Adder Logisim

40 Logisim is FREE logic gate simulation software
Please download / install this software It should be on the lab machines, too

41 Download / install Logisim Complete homework #2
Next Steps Download / install Logisim Complete homework #2 Data representation Binary arithmetic Create (useful) logic gate circuits using Logisim Next lecture: Micro-architecture


Download ppt "Outline Binary Addition 2’s complement Binary Subtraction Half Adder"

Similar presentations


Ads by Google