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.

Slides:



Advertisements
Similar presentations
Floating Point Numbers
Advertisements

Signed Numbers.
2-1 Computer Organization Part Fixed Point Numbers Using only two digits of precision for signed base 10 numbers, the range (interval between lowest.
Floating Point Numbers
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
Signed Numbers CS208. Signed Numbers Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers.
1 Binary Numbers Again Recall that N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to bits.
Floating Point Numbers.  Floating point numbers are real numbers.  In Java, this just means any numbers that aren’t integers (whole numbers)  For example…
Operations on data CHAPTER 4.
Binary Representation - Shortcuts n Negation x + x = 1111…1111 two = -1 (in 2’s complement) Therefore, -x = x + 1 n Sign Extension o Positive numbers :
The Binary Number System
Data Representation Number Systems.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Integer Data representation Addition and Multiplication.
Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.
Number Representation
Operations on Bits Arithmetic Operations Logic Operations
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
CEC 220 Digital Circuit Design Binary Arithmetic & Negative Numbers Monday, January 13 CEC 220 Digital Circuit Design Slide 1 of 14.
CEC 220 Digital Circuit Design Binary Arithmetic & Negative Numbers Fri, Aug 28 CEC 220 Digital Circuit Design Slide 1 of 14.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Chapter 4 Operations on Bits. Apply arithmetic operations on bits when the integer is represented in two’s complement. Apply logical operations on bits.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
Nguyen Le CS147.  2.4 Signed Integer Representation  – Signed Magnitude  – Complement Systems  – Unsigned Versus Signed Numbers.
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
Unit I From Fundamentals of Logic Design by Roth and Kinney.
Negative Number Sign-Magnitude: left-most bit as the sign bit –16 bits –Example: 4-bit numbers is given by is given by ’s complement:
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Floating Point Numbers Dr. Mohsen NASRI College of Computer and Information Sciences, Majmaah University, Al Majmaah
Floating Point Numbers
Cosc 2150: Computer Organization
David Kauchak CS 52 – Spring 2017
Computer Architecture & Operations I
Addition and Subtraction
Digital Logic & Design Adil Waheed Lecture 02.
Lec 3: Data Representation
Binary -ve and +ve numbers!.
Integers Rules of Operation.
Chapter 4 Operations on Bits.
CHAPTER 9 COMPUTER ARITHMETIC - ALU
3.1 Denary, Binary and Hexadecimal Number Systems
Introduction To Computer Science
Recap Add these numbers together in binary
Digital Logic & Design Dr. Waseem Ikram Lecture 02.
Integer Real Numbers Character Boolean Memory Address CPU Data Types
Computer Science 210 Computer Organization
Computer Architecture & Operations I
Negative Binary Numbers
CSE 102 Introduction to Computer Engineering
Data Structures Mohammed Thajeel To the second year students
Computer Science 210 Computer Organization
Fundamentals of Programming I Number Systems
Data Representation in Computer Systems
Fundamentals of Data Representation
Digital Logic & Design Lecture 02.
1.6) Storing Integer:.
CS 101 – Sept. 4 Number representation Integer Unsigned √ Signed √
C1 Number systems.
Number Representation
Binary “There are 10 types of people in the world: Those who understand binary, and those who don't.”
How are negative and rational numbers represented on the computer?
Chapter 6: Computer Arithmetic
Binary to Decimal Conversion
CSC 220: Computer Organization Signed Number Representation
COMS 361 Computer Organization
Chapter3 Fixed Point Representation
GCSE COMPUTER SCIENCE Topic 3 - Data 3.3 Logical and Arithmetic Shifts.
OBJECTIVES After reading this chapter, the reader should be able to :
靜夜思 床前明月光, 疑是地上霜。 舉頭望明月, 低頭思故鄉。 ~ 李白 李商隱.
Two’s Complement & Binary Arithmetic
Presentation transcript:

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