Presentation is loading. Please wait.

Presentation is loading. Please wait.

Binary Arithmetic Binary arithmetic is essential in all digital computers and in many other types of digital systems. Addition, Subtraction, Multiplication,

Similar presentations


Presentation on theme: "Binary Arithmetic Binary arithmetic is essential in all digital computers and in many other types of digital systems. Addition, Subtraction, Multiplication,"— Presentation transcript:

1 Binary Arithmetic Binary arithmetic is essential in all digital computers and in many other types of digital systems. Addition, Subtraction, Multiplication, and Division

2 Binary Addition Example:
The four basic rules for adding binary digits (bits) are as follows: 0 + 0 = 0 sum of 0 with a carry of 0 0 + 1 = 1 sum of 1 with a carry 0f 0 1 + 0 = 1 sum of 1 with a carry of 0 1+ 1 = 10 sum of 0 with a carry 0f 1 1 1 0 1 1 1 0 0 Carry Example: Try This: = ??

3 Binary Subtraction Example:
The four basic rules for subtracting bits are as follows: 0 – 0 = 0 with borrow 0 1 – 1 = 0 with borrow 0 1 – 0 = 1 with borrow 0 10 – 1 = – 1 with a borrow of 1 1 1 – 0 1 = ?? 1 1 0 1 1 0 Example: Try This: 1 0 1 – = ???

4 Binary Subtraction Have previously looked at the subtraction operation. A quick review. Just like subtraction in any other base Minuend Subtrahand Difference And when a borrow is needed. Note that the borrow gives us 2 in the current bit position. .

5 And a full example And more ripple -

6 In General When there is no borrow into the msb position, then the subtrahend in not larger than the minuend and the result is positive and correct. If a borrow into the msb does occur, then the subtrahend is larger than the minuend.

7 Consider Now do the operation 4 – 6 Correct difference is -2 or -0010

8 Two’s compliment But how do you represent a minus sign electronically in a computer? How can you represent it such that arithmetic operations are manageable? There are two types of compliments for each number base system. Have the r’s complement Have the (r-1)’s complement For base have 2’s complement and 1’s complement

9 1’s Complement 1’s complement of N is defined as (2n -1)-N.
If n=4 have (2n -1) being = 1111 So for n=4 would subtract any 4-bit binary number from 1111. This is just inverting each bit. Example: 1’s compliment of is

10 2’s complement The 2’s complement is defined as 2n-N
Can be done by subtraction of N from 2n or adding 1 to the 1’s complement of a number. For 6 = 0110 The 1’s complement is 1001 The 2’s complement is 1010

11 Operation with 2’s complement
Add 4 and -6 Will use the 2’s complement of -6 or 1010 1110 And taking the 2’s complement of 1110 get = 0010

12 Binary Multiplication
The four basic rules for multiplying bits are as follows: 0 X 0 = 0 0 X 1 = 0 1 X 0 = 0 1 X 1 = 1 1 1 X 1 1 = ?? 1 1 X 1 1 +1 1 Try This: 1 1 1 X = ?? Example:

13 Binary Division Example:
Division in binary follows the same procedure as division in decimal. 1 1 0 ÷ 11 = ?? 1 0 1 1 0 0 0 Example: Try This: 1 1 0 ÷ 10 = ??

14 Representing Negative Numbers
As there is no third symbol available to store a negative symbol explicitly we must use a bit to show if a number is negative or not. We name this bit the ‘Sign Bit’ We use the leftmost bit. If the ‘Sign Bit’ is 1 then the number is negative, if it is 0 then it is positive.

15 Representing Negative Numbers - Sign & Magnitude
At first glance it may appear to be simple from this point, for example: 3 = so -3 = Sign Bits

16 Representing Negative Numbers - Sign & Magnitude
The problem with this method is that arithmetic is inconvenient: e.g = 0 but i.e. not 0

17 Two’s Complement This is a better way to represent negative numbers.
Imagine a km clock in a car set at kilometres. If the car goes forward one km the reading becomes If the meter was turned back one km the reading would be km. This could be interpreted as ‘-1’ km.

18 -5 -5 = 11111011 Work out the binary number as if it were positive.
5 = From the left, flip all bits up to the last ‘1’, leave this and any other bits after that alone. -5 = Don’t flip the last 1. 1 1 1 1 1 1 1

19 1’s and 2’s Complements of Binary Numbers
The 1’s and 2’s Complements of Binary Numbers are very important because they permit the representation of negative numbers. The method of 2’s compliment arithmetic is commonly used in computers to handle negative numbers

20 Finding the 1’s Complement
The 1’s complement of a binary number is found by changing all 1s to 0s and all 0s to 1s. Example: (Binary Number) (1’s Complement) NOT Gate

21 From the left, flip all bits up to the last ‘1’, leave this and any other bits after that alone. Work out the decimal number as if it were positive. = 5 Add the minus sign. = -5 04/07/2018

22 Finding the 2’s Complement
The 2’s complement of a binary number is found by adding 1 to the LSB of the 1’s complement 2's Complement = (1's Complement) + 1 Find the 2’s complement of (Binary number) (1’s complement) 1 (Add 1) Example:

23 Signed Numbers Digital systems, such as the computer, must be able to handle both positive and negative numbers. A signed binary number consists of both sign and magnitude information. The sign indicates whether a number is positive or negative and the magnitude is the value of the number. There three forms in which signed integer (whole) numbers can be represented in binary: Sign-Magnitude 1’s Complement 2’s Complement

24 0 = Positive Number and 1 = Negative Number
The Sign Bit The left-most bit in a signed binary number is the sign bit, which tells you whether the number is positive or negative. 0 = Positive Number and 1 = Negative Number Sign-Magnitude Form When a signed binary number is represented in sign-magnitude, the left-most bit is the sign bit and the remaining bits are the magnitude bits. The magnitude bits are in true (uncomplemented) binary for both positive and negative numbers. Decimal number, +25 is expressed as an 8-bit signed binary number using sign-magnitude form as: Example: Magnitude Bit Sign Bit

25 1’s Complement Form Positive numbers in 1’s complement form are represented the same way as the positive sign-magnitude numbers. Negative numbers, however, are the 1’s complements of the corresponding positive numbers. Example: The decimal number -25 is expressed as the 1’s complement of +25 ( ) as ( ) 2’s Complement Form In the 2’s complement form, a negative number is the 2’s complement of the corresponding positive number

26 Example: Sign-Magnitude: 1's Complement: 2's Complement: 00100111
Express the decimal number -39 in sign-magnitude, 1’s complement and 2’s complement Sign-Magnitude: >>> 1's Complement: >>> 2's Complement: >>>

27 Arithmetic Operations with Signed Number
2’s complement arithmetic used in computers and microprocessor-based system .

28 1’s Complement Addition
Using 1’s complement numbers, adding numbers is easy. For example, suppose we wish to add +(1100)2 and +(0001)2. Let’s compute (12)10 + (1)10.

29 1’s Complement Addition
(12)10 = +(1100)2 = (1)10 = +(0001)2 = Add carry Final Result Step 1: Add binary numbers Step 2: Add carry to low-order bit

30 1’s Complement Subtraction
Let’s compute (12)10 - (1)10. (12)10 = +(1100)2 = (-1)10 = -(0001)2 = in 1’s comp.

31 1’s Complement Subtraction
Step 1: Take 1’s complement of 2nd operand Step 2: Add binary numbers Step 3: Add carry to low order bit 1

32 2’s Complement Addition
Using 2’s complement numbers, adding numbers is easy. For example, suppose we wish to add +(1100)2 and +(0001)2. Let’s compute (12)10 + (1)10. Add Step 1: Add binary numbers Step 2: Ignore carry bit Final Result Ignore

33 2’s Complement Subtraction
Using 2’s complement numbers, follow steps for subtraction Let’s compute (12)10 - (1)10. (12)10 = +(1100)2 = (-1)10 = -(0001)2 = in 2’s comp.

34 2’s Complement Subtraction
Step 1: Take 2’s complement of 2nd operand Step 2: Add binary numbers Step 3: Ignore carry bit 2’s comp Add Final Result Ignore Carry

35 2’s Complement Subtraction: Example #2
Let’s compute (13)10 – (5)10. (13)10 = +(1101)2 = (01101)2 (-5)10 = -(0101)2 = (11011)2 Adding these two 5-bit codes… Discarding the carry bit, the sign bit is seen to be zero, indicating a correct result. Indeed, (01000)2 = +(1000)2 = +(8)10. carry

36 2’s Complement Subtraction: Example #3
Let’s compute (5)10 – (12)10. (-12)10 = -(1100)2 = (10100)2 (5)10 = +(0101)2 = (00101)2 Adding these two 5-bit codes… Here, there is no carry bit and the sign bit is 1. This indicates a negative result, which is what we expect. (11001)2 = -(7)10. If final answer is –ve answer will be in two’s complement

37 BCD Binary Coded Decimal (BCD) is another way to present decimal numbers in binary form. BCD is widely used and combines features of both decimal and binary systems. Each digit is converted to a binary equivalent.

38 BCD To convert the number 87410 to BCD: 8 7 4
8 7 4 = BCD Each decimal digit is represented using 4 bits. Each 4-bit group can never be greater than 9. Reverse the process to convert BCD to decimal.

39 BCD BCD is not a number system.
BCD is a decimal number with each digit encoded to its binary equivalent. A BCD number is not the same as a straight binary number. The primary advantage of BCD is the relative ease of converting to and from decimal.

40 Alphanumeric Codes Represents characters and functions found on a computer keyboard. ASCII – American Standard Code for Information Interchange. Seven bit code: 27 = 128 possible code groups Examples of use are: to transfer information between computers, between computers and printers, and for internal storage.

41 Gray Code Gray code is not a number system.
Digit Binary Gray Code 0000 1 0001 2 0010 0011 3 4 0100 0110 5 0101 0111 6 7 8 1000 1100 9 1001 1101 10 1010 1111 11 1011 1110 12 13 14 15 Gray code is not a number system. It is an alternate way to represent four bit data Only one bit changes from one decimal digit to the next Useful for reducing errors in communication. Can be scaled to larger numbers. credential: bring a computer die photo wafer : This can be an hidden slide. I just want to use this to do my own planning. I have rearranged Culler’s lecture slides slightly and add more slides. This covers everything he covers in his first lecture (and more) but may We will save the fun part, “ Levels of Organization,” at the end (so student can stay awake): I will show the internal stricture of the SS10/20. Notes to Patterson: You may want to edit the slides in your section or add extra slides to taylor your needs.

42 Parity Codes Parity codes are formed by concatenating a parity bit, P to each code word of C. In an odd-parity code, the parity bit is specified so that the total number of ones is odd. In an even-parity code, the parity bit is specified so that the total number of ones is even. Information Bits P Added even parity bit Added odd parity bit


Download ppt "Binary Arithmetic Binary arithmetic is essential in all digital computers and in many other types of digital systems. Addition, Subtraction, Multiplication,"

Similar presentations


Ads by Google