Integers Whole numbers Do NOT contain decimal points
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 973 cs 111_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 bits 0 through 255 16 bits 0 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 973 cs 111_add_posneg. ppt
Signed Integers A number can be positive or negative The high order bit determines if + or – 1 0 0 1 is a negative number 0 0 1 0 1 is a positive number 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) 973 cs 111_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 973 cs 111_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 0 1 is a negative number 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: 00001110 Weight values total to 14 High bit is a 0 therefore the number is positive The number is +14 (this is the magnitude) 10001110 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) 973 cs 111_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 12 is a positive +3710 (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 +3710 = 1 1 0 1 02 is the One’s Complement of +3710 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. 973 cs 111_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 973 cs 111_add_posneg. ppt
Conversion Rule To convert to or from a + or – binary number do: One’s Complement first Then Two’s Complement 973 cs 111_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 973 cs 111_add_posneg. ppt
Convert Binary to Decimal Signed Integers Negative to Positive Binary Conversion Given the negative binary #: 10001110 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 (-) Binary Number One’s Complement Two’s Complement 1 10001110001 973 cs 111_add_posneg. ppt 01110001 + 1 -------01110010 = 11410
Two’s Complement ADDITION Unsigned: 5 +3 --8 1 1 1 5 = 0 12 3 = 0 0 1 12 ----8 = 1 0 0 02 No One’s or Two’s Complement required Signed: high order bit = sign (+ or -) 5 +3 --8 1 1 1 5 = 0 12 +3 = 0 0 1 12 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 973 cs 111_add_posneg. ppt
Two’s Complement Subtraction Is accomplished through Addition Unsigned Subtraction 1) 510 (+) -310 ---210 2) 5 = 01012 3 = 11002 One’s Complement on the negative 3 1 3) 5=0101 3=1100 -----1 0 0 0 1 Add the two numbers 4) 5=0101 3=1100 -----0001 1 Add binary one (Two’s Complement) ----0 0 1 0 = 210 973 cs 111_add_posneg. ppt
Two’s Complement Subtraction Is accomplished through Addition Signed Subtraction 1) 510 (+) -310 ---210 2) 0011 = 1100 complement = a -3 find the value of a -3 bit pattern 5 = 01012 3 = 11002 Rule 1: do One’s Complement 1 3) 4) 5=0101 3=1100 -----1 0 0 0 1 Rule 2: Add 5=0101 3=1100 -----0001 1 Rule 3: Two’s Complement ----0 0 1 0 = 210 Magnitude (Value) of the positive result is 2 970 cs 111_objects 1. ppt 973 cs 111_add_posneg. ppt
Two’s Complement Subtraction Is accomplished through Addition Signed Subtraction 1) 310 (+) -510 ----210 0011 0101 ? 2) -5 = 1010 3) Rule 1: do One’s Complement 3=0011 -5 = 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 = -210 bit pattern for a +2 973 cs 111_add_posneg. ppt
Two’s Complement Subtraction Confirmation Is accomplished through Addition Signed Subtraction Find out the real value of this negative number 1) ? 1110 2) 0001 (a negative 2? ) 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 973 cs 111_add_posneg. ppt
Two’s Complement Subtraction: another sample Is accomplished through Addition Signed Subtraction 1) 6210 (+) -7510 ----210 00111110 01001011 ? 2) -75 = 1 0 1 0 0 Rule 1: do One’s Complement 1 1 3) 62 = 0 0 1 1 1 0 -75 = 1 0 1 0 0 ----------11110010 Rule 2: Add 1 1 0 0 1 0 Rule 3: Two’s Complement 1 Add binary one ---------1 1 0 0 1 1 = -1310 bit pattern for a +13 973 cs 111_add_posneg. ppt
Two’s Complement Subtraction Confirmation Is accomplished through Addition Signed Subtraction Find out the real value of this negative number 1) ? 11110011 2) 00001100 Rule 1: do One’s Complement 3) 0 0 1 1 0 0 Rule 2 for converting a negative # + 1 to a positive # - do Two’s ---------Complement 0 0 1 1 0 1 Binary magnitude of 13 973 cs 111_add_posneg. ppt
Conversions Convert a POSITIVE number to a NEGATIVE number +2 0010 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 1110 1 0 0 0 1 Take One’s Complement of -2 1 Do Two’s Complement -----0 0 1 0 = +2 version of -2 973 cs 111_add_posneg. ppt
- Slides: 18