Two’s and one’s complement arithmetic. 12 3 6 9 1 2 4 5 7 8 10 11 CLOCK ARITHMETIC.

Slides:



Advertisements
Similar presentations
Lab 10 : Arithmetic Systems : Adder System Layout: Slide #2 Slide #3 Slide #4 Slide #5 Arithmetic Overflow: 2’s Complement Conversions: 8 Bit Adder/Subtractor.
Advertisements

Number Bases Informatics INFO I101 February 9, 2004 John C. Paolillo, Instructor.
HEXADECIMAL NUMBERS Code
Addition and Subtraction. Outline Arithmetic Operations (Section 1.2) – Addition – Subtraction – Multiplication Complements (Section 1.5) – 1’s complement.
ELEC353 S. al Zahir UBC Sign-Magnitude Representation High order bit is sign: 0 = positive (or zero), 1 = negative Low order bits represent the magnitude:
Addition of two binary numbers = = = = 39.
1 CSE1301 Computer Programming Lecture 29: Number Representation (Part 1)
Parallel Adder Recap To add two n-bit numbers together, n full-adders should be cascaded. Each full-adder represents a column in the long addition. The.
King Fahd University of Petroleum and Minerals
Digital Fundamentals Floyd Chapter 2 Tenth Edition
Wakerly Section 2.4 and further Addition and Subtraction of Nondecimal Numbers.
Assembly Language and Computer Architecture Using C++ and Java
Fixed-Point Arithmetics: Part I
Kavita Hatwal Fall The decimal system, also called the base 10 number system is based on ten numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. All the numbers.
Signed Numbers.
Assembly Language and Computer Architecture Using C++ and Java
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)
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.
1 Lecture 2: Number Systems Binary numbers Base conversion Arithmetic Number systems  Sign and magnitude  Ones-complement  Twos-complement Binary-coded.
Chapter 3 Data Representation part2 Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
NEGATIVE BINARY NUMBER – Digital Circuit 1 Choopan Rattanapoka.
1.6 Signed Binary Numbers.
Dr. Bernard Chen Ph.D. University of Central Arkansas
Binary Addition Addition Rules: = = = = = carry 1 1 carry 1 Example 1: Example 2:
Chapter3 Fixed Point Representation Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Fundamentals Tenth Edition Floyd.
Lecture for Week Spring.  Numbers can be represented in many ways. We are familiar with the decimal system since it is most widely used in everyday.
Copyright © Cengage Learning. All rights reserved. CHAPTER 2 THE LOGIC OF COMPOUND STATEMENTS THE LOGIC OF COMPOUND STATEMENTS.
Computer Arithmetic Nizamettin AYDIN
Number Systems Part 2 Numerical Overflow Right and Left Shifts Storage Methods Subtraction Ranges.
Data Representation in Computer Systems
Topic: Arithmetic Circuits Course: Digital Systems Slide no. 1 Chapter # 5: Arithmetic Circuits.
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
CPS120: Introduction to Computer Science Computer Math: Signed Numbers.
CSE 241 Computer Organization Lecture # 9 Ch. 4 Computer Arithmetic Dr. Tamer Samy Gaafar Dept. of Computer & Systems Engineering.
Calculating Two’s Complement. The two's complement of a binary number is defined as the value obtained by subtracting the number from a large power of.
Computer Arithmetic and the Arithmetic Unit Lesson 2 - Ioan Despi.
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
BR 8/99 Binary Numbers Again Recall than N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to 255.
1 IT 231, CMPE 331 Digital Logic Design Week 2 Number systems and arithmetic.
Topic 1 – Number Systems. What is a Number System? A number system consists of an ordered set of symbols (digits) with relations defined for addition,
Charles Kime & Thomas Kaminski © 2004 Pearson Education, Inc. Terms of Use (Hyperlinks are active in View Show mode) Terms of Use Logic and Computer Design.
Operations on Bits Arithmetic Operations Logic Operations
By Jariya Phongsai A two's-complement system is a system in which negative numbers are represented by the two's complement of the absolute value; this.
Positive and Negative numbers. Negative numbers A positive or negative whole number, including zero, is called an integer. For example, –3 is an integer.
07/12/ Data Representation Two’s Complement & Binary Arithmetic.
Addition and Substraction
Digital Logic Lecture 3 Binary Arithmetic By Zyad Dwekat The Hashemite University Computer Engineering Department.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
IT1004: Data Representation and Organization Negative number representation.
Registers and Binary Arithmetic Prof. Sirer CS 316 Cornell University.
Introduction to Digital Electronics Lecture 2: Number Systems.
ECE DIGITAL LOGIC LECTURE 3: DIGITAL COMPUTER AND NUMBER SYSTEMS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2016, 01/19/2016.
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN Lecture 8 Dr. Shi Dept. of Electrical and Computer Engineering.
Integer Operations Computer Organization and Assembly Language: Module 5.
MicroProcessors Lec. 4 Dr. Tamer Samy Gaafar. Course Web Page —
Chapter 8 Computer Arithmetic. 8.1 Unsigned Notation Non-negative notation  It treats every number as either zero or a positive value  Range: 0 to 2.
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
ECE 3110: Introduction to Digital Systems Signed Number Conversions and operations.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
Arithmetic Circuits I. 2 Iterative Combinational Circuits Like a hierachy, except functional blocks per bit.
Representing Positive and Negative Numbers
Data Structures Mohammed Thajeel To the second year students
Arithmetic Logical Unit
CPS120: Introduction to Computer Science
Copyright © Cengage Learning. All rights reserved.
Chapter3 Fixed Point Representation
Two’s Complement & Binary Arithmetic
Presentation transcript:

Two’s and one’s complement arithmetic

CLOCK ARITHMETIC

= ?

= 5; 9+4=?

= 5; 9+4=13=1; 7*3=?

= 5; 9+4=13=1; 7*3=21=9

12= = 5; 9+4=13=1; 7*3=21=9 You can add and multiply in clock arithmetic; but you subtract multiples of 12 to get the clock display (between 1 and 12) (or, better, between 0 and 11). In particular, you can perform accurate, real arithmetic on a clock (without correction), as long as you ensure your calculations don’t go beyond [0,11].

A base-16 clock = ?; = ?

= 7; = (24-16) = 8.

It’s easy for a computer to do base-16 clock arithmetic if the numbers are encoded in binary

Whenever a sum in base-16 clock arithmetic is 16 or greater, it acquires a fifth bit. 13 or To subtract 16 in the binary form, || || simply drop the fifth bit (since 16 = ). So to do base 16 arithmetic, use a binary 4-bit register and drop the “carry” if it occurs in the 4 th bit.

A base-15 clock = ?; = ?

3+4 = 7; =

To implement base-15 arithmetic on a computer, again use the binary representation:

Whenever a sum in base-15 clock arithmetic exceeds 15, it acquires a fifth bit. 13 or Subtract 15 || || The easy way to subtract 15 in binary is to subtract 16 and add 1. Subtract 16 by removing the fifth bit. Then to add 1 you can imagine that the fifth bit is “carried around” to the first bit ______ 0011 So you can do base-15 clock arithmetic with standard bit-adders, linking the 4 th - bit carry to the first bit.

So it’s easy to use standard bit-adders to do base-2 n clock arithmetic; simply drop the “carry” in the final bit. And it’s almost as easy to use standard adders to do base-[2 n -1] clock arithmetic; simply connect the “carry” in the final bit to the first bit. Next we will show how to interpret clock arithmetic in these two systems as signed arithmetic. We will not alter the computations or the hardware; we will simply interpret the numbers differently.

Can you subtract on a standard clock? Are there negative numbers? = ?

Can you subtract on a standard clock? Are there negative numbers? = 9 5

(-1) is the solution to x + 1 = 0. So (-1) = 11. And (-2) = 10. (-1) (-2) Of course this respects the rule, because (-1) + 12 = 11; (-2) + 12 = 10.

(-1) (-2) Therefore clock arithmetic replicates real arithmetic for numbers between (-6) and +5, if we identify 11 with -1, 10 with -2, …, 6 with -6. (-3) (-4) (-5) (-6) (0) (1) (2) (3) (4) (5) (-3) + 2 = -1 because = 11 ; (-3) + 5 = 2 because = 2 on the clock.

(-1) (-2) For example we can compute 3 – 5 = 3 +(-5) by adding the clock version of (-5) to 3. (-3) (-4) (-5) (-6) (0) (1) (2) (3) (4) (5) (-5) (+7) 3 – 5 = = 10 = -2.

So the rules for signed clock arithmetic are: 1. Make sure your calculations don’t call for any numbers beyond [-6,5]. 2. Identify -1 with 11, -2 with 10, -3 with 9, -4 with 8, -5 with 7, -6 with Perform the signed addition [like 3 – 2 = 3 + (-2)] by doing the normal addition with clock arithmetic, using 0 through 11. (So if any answer lies outside [0,11], “repair” it by adding or subtracting 12.) 4. Identify 11 with with -2, 9 with -3, 8 with with -5, and 6 with -6. The hard parts, for computer implementation, are (i) making it easy to look at a coded negative number and identify its positive twin in steps 2 and 4. (ii) repairing any answer that lies out of the range in step 3. We have seen how the binary representation of the clock numbers makes (ii) very easy if the clock has 2 n or 2 n -1 numbers. Now we will show how 2’s complement and 1’s complement arithmetic, in the binary system, simplify (i).

Identify the negative numbers on the base-16 (=2 4 ) clock (0) (1) (2) (3) (4) (5) (6) (7)(-8) (-7) (-6) (-5) (-4) (-3) (-2) (-1)

Now write the original clock numbers in binary form. (0) (1) (2) (3) (4) (5) (6) (7)(-8) (-7) (-6) (-5) (-4) (-3) (-2) (-1)

Recall our first objective: “(i) making it easy to identify negative numbers with their positive twins…” It’s easy to identify the negative numbers: their leading digit is “1”. (0) (1) (2) (3) (4) (5) (6) (7)(-8) (-7) (-6) (-5) (-4) (-3) (-2) (-1)

Recall our first objective: “(i) making it easy to identify negative numbers with their positive twins…” Get the positive twin by subtracting the number from 16 ( ). (0) (1) (2) (3) (4) (5) (6) (7)(-8) (-7) (-6) (-5) (-4) (-3) (-2) (-1) = = =

Recall our first objective: “(i) making it easy to identify negative numbers with their positive twins…” Get the positive twin by subtracting the number from 16 ( ). (0) (1) (2) (3) (4) (5) (6) (7)(-8) (-7) (-6) (-5) (-4) (-3) (-2) (-1) = = = = = = = =0001

Recall our first objective: “(i) making it easy to identify negative numbers with their positive twins…”. If the binary number starts with 0, interpret it as a positive number or zero. If the binary number starts with 1, interpret it as the negative of [ minus the number]. This is called (the negative of) the 2’s complement of the number.

(0) (1) (2) (3) (4) (5) (6) (7)(-8) (-7) (-6) (-5) (-4) (-3) (-2) (-1)

CONCLUSION The 2’s complement system The 2’s complement system codes numbers with n bits. n = 4 in our example. Positive numbers from 0 to 2 n-1 -1 are written in standard binary notation, and are identified by that fact that their leading bit is zero. 0 to 7 in our example. Negative numbers from –2 n-1 to -1 are coded as their “2’s complement’, which is 2 n minus the absolute value of the number, and are identified by the fact that their leading bit is one. -8 to -1 in our example. Calculations are performed using ordinary arithmetic with the numbers binary coded, using an n-bit register, and dropping any “carry” in the n th bit. The user must avoid overflow, which occurs if any number larger than [2 n-1 -1] or lower that -2 n-1 is computed.

How about negative numbers on a base-15 clock? =?

How about negative numbers on a base-15 clock? =12 7

The negative numbers are as shown: (0) (1) (2) (3) (4) (5) (6) (7) (-7) (-6) (-5) (-4) (-3) (-2) (-1)

Now write the original numbers in binary form. Note that 0 (which is equivalent to 15) has two representations now, as 0000 and as (0) (1) (2) (3) (4) (5) (6) (7) (-7) (-6) (-5) (-4) (-3) (-2) (-1)

Recall our first objective: “(i) making it easy to identify negative numbers with their positive twins…” Again it’s easy to identify the negative numbers: their leading digit is “1”. (Sometimes we call 1111 the “negative zero.”) (0) (1) (2) (3) (4) (5) (6) (7) (-7) (-6) (-5) (-4) (-3) (-2) (-1)

Recall our first objective: “(i) making it easy to identify negative numbers with their positive twins…” Get the positive twin by subtracting the number from 15, i.e. ( ). (0) (1) (2) (3) (4) (5) (6) (7) (-7) (-6) (-5) (-4) (-3) (-2) (-1) = = =

(0) (1) (2) (3) (4) (5) (6) (7) (-7) (-6) (-5) (-4) (-3) (-2) (-1) Recall our first objective: “(i) making it easy to identify negative numbers with their positive twins…” Get the positive twin by subtracting the number from 15, i.e. ( ). This is too easy. Change every 1 to 0 and every 0 to 1.

Recall our first objective: “(i) making it easy to identify negative numbers with their positive twins…”. If the binary number starts with 0, interpret it as a positive number or zero. If the binary number starts with 1, interpret it as the negative of the number obtained by changing each bit. This the (the negative of) the 1’s complement of the number.

(0) (1) (2) (3) (4) (5) (6) (7) (-7) (-6) (-5) (-4) (-3) (-2) (-1)

CONCLUSION The 1’s complement system The 1’s complement system codes numbers with n bits. n = 4 in our example Positive numbers from 0 to (2 n-1 -1) are written in standard binary notation, and are identified by that fact that their leading bit is zero. 0 to 7 in our example Negative numbers from –(2 n-1 -1 ) to -1 are coded as their “1’s complement’, which means every bit is changed from 0 to 1 or from 1 to 0; and are identified by the fact that their leading bit is one. -7 to -1 in our example As a result, 0000 is identified with 1111, which is sometimes called “negative zero.” Calculations are performed using ordinary arithmetic with the numbers binary coded, using an n-bit register, except that any “carry” generated in the n th bit of a sum is carried around and added to the first bit. The user must avoid overflow, which occurs if any number larger than (2 n-1 -1) or lower that –(2 n-1 -1) is computed.