973cs111_add_posneg.ppt Integers Whole numbers Do NOT contain decimal points (as in money) 43,689 is an integer 43, 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
973cs111_add_posneg.ppt Unsigned Integers Whole numbers (integer) Do NOT contain decimal points (as in money) 43,689 is an integer 43, is NOT an integer (it is floating point) Sample Ranges: 4 bits 0 through 15 8 bits0 through bits0 through 65,535 Ex. Using 8 bits: Decimal 165 has a bit pattern of Decimal 37 has a bit pattern of 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
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 – is a negative number is a positive number
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
973cs111_add_posneg.ppt Convert Binary to Decimal Signed Integers A number can be positive or negative The high order bit determines if + or – is a negative number 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: Weight values total to 14 High bit is a 0 therefore the number is positive The number is +14 (this is the magnitude) 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)
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 is a positive (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 = is the One’s Complement of 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.
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: positive binary byte (high order bit 0) + 1 Two’s Complement Two’s Complement result 1 Given: negative binary byte (high order bit 1) + 1 Two’s Complement Two’s Complement result This results in the Two’s Compliment number
973cs111_add_posneg.ppt Conversion Rule To convert to or from a + or – binary number do: One’s Complement first Then Two’s Complement
973cs111_add_posneg.ppt Convert Binary to Decimal Signed Integers Positive to negative number: Given binary positive byte = +2 1)One’s Complement the byte: = unknown # 1 2) Two’s Complement the byte: = -2 Representation Negative to positive number: Given binary negative byte = -2 1)One’s Complement the byte: = unknown # 1 2) Two’s Complement the byte: = +2
973cs111_add_posneg.ppt Convert Binary to Decimal Signed Integers Negative to Positive Binary Conversion Given the negative binary #: 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 =
973cs111_add_posneg.ppt Two’s Complement Unsigned: = = = No One’s or Two’s Complement required Signed: high order bit = sign (+ or -) = = the only valid results are 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
973cs111_add_posneg.ppt Two’s Complement Is accomplished through Addition Unsigned Subtraction 1) 5 10 (+) ) 5 = = One’s Complement on the negative 3 1 3) 5 = = Add the two numbers 4) 5 = = Add binary one (Two’s Complement) = 2 10 Subtraction
973cs111_add_posneg.ppt 970cs111_objects1.ppt Two’s Complement Is accomplished through Addition Signed Subtraction 1) 5 10 (+) = 1100 complement = a find the value of a -3 bit pattern ) 5 = = Rule 1: do One’s Complement 1 3) 5 = = Rule 2: Add 4) 5 = = Rule 3: Two’s Complement = 2 10 Magnitude (Value) of the positive result is 2 Subtraction
973cs111_add_posneg.ppt Two’s Complement Is accomplished through Addition Signed Subtraction 1) (+) ? 2)-5 = 1010 Rule 1: do One’s Complement 3) 3 = = Rule 2: Add 1 4) Rule 3: Two’s Complement 1 Add binary one = bit pattern for a +2 Subtraction
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) Rule 2 for converting a negative # to a + 1 positive # - do Two’s Complement Binary magnitude of 2 Subtraction Confirmation
973cs111_add_posneg.ppt Two’s Complement Is accomplished through Addition Signed Subtraction 1) (+) ? 2)-75 = Rule 1: do One’s Complement ) 62 = = Rule 2: Add Rule 3: Two’s Complement 1 Add binary one = bit pattern for a +13 Subtraction: another sample
973cs111_add_posneg.ppt Two’s Complement Is accomplished through Addition Signed Subtraction Find out the real value of this negative number 1)? ) Rule 1: do One’s Complement 3) Rule 2 for converting a negative # + 1 to a positive # - do Two’s Complement Binary magnitude of 13 Subtraction Confirmation
973cs111_add_posneg.ppt Conversions Convert a POSITIVE number to a NEGATIVE number Take One’s Complement of +2 1 Do Two’s Complement = -2 version of +2 Convert a NEGATIVE number to a POSITIVE number Take One’s Complement of -2 1 Do Two’s Complement = +2 version of -2