Presentation is loading. Please wait.

Presentation is loading. Please wait.

973cs111_add_posneg.ppt Integers Whole numbers Do NOT contain decimal points (as in money) 43,689 is an integer 43,689.24 is NOT an integer (it is floating.

Similar presentations


Presentation on theme: "973cs111_add_posneg.ppt Integers Whole numbers Do NOT contain decimal points (as in money) 43,689 is an integer 43,689.24 is NOT an integer (it is floating."— Presentation transcript:

1 973cs111_add_posneg.ppt Integers Whole numbers Do NOT contain decimal points (as in money) 43,689 is an integer 43,689.24 is NOT an integer (it is floating point) Overflow A number of bits are allocated to hold a number: such as a byte (8 bits) or a word (4 bytes) The numeric data (number) being placed into the address is larger than the allocated # of bits can hold The program will abend (abnormal termination – blow off) Ex. Using 8 bits (standard byte) Will hold the numbers 0 through 255 Try to put the number 306 into the byte and an overflow occurs

2 973cs111_add_posneg.ppt Unsigned Integers Whole numbers (integer) Do NOT contain decimal points (as in money) 43,689 is an integer 43,689.24 is NOT an integer (it is floating point) Sample Ranges: 4 bits 0 through 15 8 bits0 through 255 16 bits0 through 65,535 Ex. Using 8 bits: Decimal 165 has a bit pattern of 10100101 Decimal 37 has a bit pattern of 00100101 Note: the highest bit can be either a 1 or a 0. The number is still a positive (+) number Add the weight values to determine the decimal value Unsigned integers are positive by default

3 973cs111_add_posneg.ppt Magnitude (size) of a Number The magnitude of a number can only be determined if the number is positive A negative number has already been converted (by One’s Compliment) and is not representative of the true value A negative number must be converted to positive number to determine the true magnitude of the number (do One’s Complement then Two’s Complement) The bits below the sign bit determine the magnitude of the number (the 1 st 7 bits of an 8 bit byte – the 8 th bit is the sign) Signed Integers A number can be positive or negative The high order bit determines if + or – 1 0 1 0 0 1 0 1 is a negative number 0 0 1 0 0 1 0 1 is a positive number

4 973cs111_add_posneg.ppt A computer does not do: Subtraction Multiplication Division All arithmetic is done with ADDITION Addition is accomplished via the use of two methods: One’s Compliment Method Two’s Compliment Method

5 973cs111_add_posneg.ppt Convert Binary to Decimal Signed Integers A number can be positive or negative The high order bit determines if + or – 1 0 1 0 0 1 0 1 is a negative number 0 0 1 0 0 1 0 1 is a positive number If a number is positive (+) just add up the weights of the bits If a number is negative (-) = left (upper) most bit is a 1 The left (upper) most bit will be a 1 therefore the number is negative To determine the true value of the #: Do the Ones’ then Two’s Complement Given: 0 0 0 0 1 1 1 0 Weight values total to 14 High bit is a 0 therefore the number is positive The number is +14 (this is the magnitude) 1 0 0 0 1 1 1 0 High bit is a 1 therefore the number is negative The true value is unknown (this is not the magnitude of the number – the magnitude is determined by the number being positive – the number will have to be One’s Complemented the Two’s Complemented)

6 973cs111_add_posneg.ppt One’s Complement The way data is stored in the computer To complement a number: Change any 0 to a 1 Change any 1 to a 0 0 0 1 0 0 1 0 1 2 is a positive +37 10 (add the weight values) stored in the computer. The number is true. Do not need to complement a positive (high order bit a 0) number to determine the magnitude. One’s Complement of the +37 10 = 1 1 0 1 1 0 1 0 2 is the One’s Complement of +37 10 High order bit is a “one” so the number is negative This does not represent the true – value (yet) A negative number is a complimented version of the positive number with the high order bit set to a 1 Only a positive number will give the true magnitude of the number.

7 973cs111_add_posneg.ppt Two’s Complement Second part of the process to convert binary numbers to/from positive and negative A computer cannot subtract, multiply, or divide A computer does all arithmetic with some form of addition Two’s Complement process Add a binary 1 to the binary byte Given: 01110010 positive binary byte (high order bit 0) + 1 Two’s Complement -------------- 01110011 Two’s Complement result 1 Given:10001101 negative binary byte (high order bit 1) + 1 Two’s Complement -------------- 10001110 Two’s Complement result This results in the Two’s Compliment number

8 973cs111_add_posneg.ppt Conversion Rule To convert to or from a + or – binary number do: One’s Complement first Then Two’s Complement

9 973cs111_add_posneg.ppt Convert Binary to Decimal Signed Integers Positive to negative number: Given binary positive byte 00000010 = +2 1)One’s Complement the byte: 11111101 = unknown # 1 2) Two’s Complement the byte: 11111101 + 1 ------------- 11111110 = -2 Representation Negative to positive number: Given binary negative byte 11111110 = -2 1)One’s Complement the byte: 00000001 = unknown # 1 2) Two’s Complement the byte: 00000001 + 1 -------------- 00000010 = +2

10 973cs111_add_posneg.ppt Convert Binary to Decimal Signed Integers Negative to Positive Binary Conversion Given the negative binary #: 1 0 0 0 1 1 1 0 High bit is a 1 therefore the number is negative The true value is unknown This is not the magnitude of the number – the magnitude is determined by the number being positive – the number will have to be One’s Complemented then Two’s Complemented The (-) BinaryOne’s ComplementTwo’s Number ComplementComplement 1 1000111001110001 01110001 + 1 -------------- 01110010 = 114 10

11 973cs111_add_posneg.ppt Two’s Complement Unsigned: 5 +3 --- 8 1 1 1 5 = 0 1 0 1 2 3 = 0 0 1 1 2 --------- 8 = 1 0 0 0 2 No One’s or Two’s Complement required Signed: high order bit = sign (+ or -) 5 +3 --- 8 1 1 1 5 = 0 1 0 1 2 +3 = 0 0 1 1 2 the only valid results are 0 - 7 --------- The addition will “blow off” with overflow High order is for the “sign” The sign going to a 1 would make it negative Only the low order bits are for the magnitude ADDITION

12 973cs111_add_posneg.ppt Two’s Complement Is accomplished through Addition Unsigned Subtraction 1) 5 10 (+) -3 10 ---- 2 10 2) 5 = 0101 2 3 = 1100 2 One’s Complement on the negative 3 1 3) 5 = 0 1 0 1 3 = 1 1 0 0 ---------- 1 0 0 0 1 Add the two numbers 4) 5 = 0 1 0 1 3 = 1 1 0 0 ---------- 0 0 0 1 1 Add binary one (Two’s Complement) --------- 0 0 1 0 = 2 10 Subtraction

13 973cs111_add_posneg.ppt 970cs111_objects1.ppt Two’s Complement Is accomplished through Addition Signed Subtraction 1) 5 10 (+) -3 10 0011 = 1100 complement = a -3 ---- find the value of a -3 bit pattern 2 10 2) 5 = 0101 2 3 = 1100 2 Rule 1: do One’s Complement 1 3) 5 = 0 1 0 1 3 = 1 1 0 0 ---------- 1 0 0 0 1 Rule 2: Add 4) 5 = 0 1 0 1 3 = 1 1 0 0 ---------- 0 0 0 1 1 Rule 3: Two’s Complement --------- 0 0 1 0 = 2 10 Magnitude (Value) of the positive result is 2 Subtraction

14 973cs111_add_posneg.ppt Two’s Complement Is accomplished through Addition Signed Subtraction 1) 3 10 0011 (+) -5 10 0101 ---- -2 10 ? 2)-5 = 1010 Rule 1: do One’s Complement 3) 3 = 0 0 1 1 -5 = 1 0 1 0 ---------- 1 1 0 1 Rule 2: Add 1 4) 1 1 0 1 Rule 3: Two’s Complement 1 Add binary one --------- 1 1 1 0 = -2 10 bit pattern for a +2 Subtraction

15 973cs111_add_posneg.ppt Two’s Complement Is accomplished through Addition Signed Subtraction Find out the real value of this negative number 1)? 1110 (a negative 2?) 2) 0001 Rule 1: do One’s Complement 1 3) 0 0 0 1 Rule 2 for converting a negative # to a + 1 positive # - do Two’s Complement ---------- 0 0 1 0 Binary magnitude of 2 Subtraction Confirmation

16 973cs111_add_posneg.ppt Two’s Complement Is accomplished through Addition Signed Subtraction 1) 62 10 0 0 1 1 1 1 1 0 (+) -75 10 0 1 0 0 1 0 1 1 ---- -2 10 ? 2)-75 = 1 0 1 1 0 1 0 0 Rule 1: do One’s Complement 1 1 1 1 3) 62 = 0 0 1 1 1 1 1 0 -75 = 1 0 1 1 0 1 0 0 --------------------- 1 1 1 1 0 0 1 0 Rule 2: Add 1 1 1 1 0 0 1 0 Rule 3: Two’s Complement 1 Add binary one ------------------- 1 1 1 1 0 0 1 1 = -13 10 bit pattern for a +13 Subtraction: another sample

17 973cs111_add_posneg.ppt Two’s Complement Is accomplished through Addition Signed Subtraction Find out the real value of this negative number 1)? 1 1 1 1 0 0 1 1 2) 0 0 0 0 1 1 0 0 Rule 1: do One’s Complement 3)0 0 0 0 1 1 0 0 Rule 2 for converting a negative # + 1 to a positive # - do Two’s ------------------- Complement 0 0 0 0 1 1 0 1 Binary magnitude of 13 Subtraction Confirmation

18 973cs111_add_posneg.ppt Conversions Convert a POSITIVE number to a NEGATIVE number +2 0 0 1 0 1 1 1 0 1 Take One’s Complement of +2 1 Do Two’s Complement ----------- 1 1 1 0 = -2 version of +2 Convert a NEGATIVE number to a POSITIVE number -2 1 1 1 0 1 0 0 0 1 Take One’s Complement of -2 1 Do Two’s Complement ----------- 0 0 1 0 = +2 version of -2


Download ppt "973cs111_add_posneg.ppt Integers Whole numbers Do NOT contain decimal points (as in money) 43,689 is an integer 43,689.24 is NOT an integer (it is floating."

Similar presentations


Ads by Google