Binary Operations Math/Logical. Binary Math Decimal Addition Example 3 7 5 8 + 4 6 5 7 1) Add 8 + 7 = 15 Write down 5, carry 1 1 8 11 415 4) Add 3 +

Slides:



Advertisements
Similar presentations
Booth's Algorithm Example
Advertisements

Intro to CS – Honors I Representing Numbers GEORGIOS PORTOKALIDIS
HEXADECIMAL NUMBERS Code
Addition and Subtraction. Outline Arithmetic Operations (Section 1.2) – Addition – Subtraction – Multiplication Complements (Section 1.5) – 1’s complement.
©Brooks/Cole, 2003 Chapter 4 Operations on Bits. ©Brooks/Cole, 2003 Apply arithmetic operations on bits when the integer is represented in two’s complement.
EMB1006 The Binary System There is no 2 Jonathan-Lee Jones.
Computer Organization & Assembly Language
King Fahd University of Petroleum and Minerals
Logical, Shift, and Rotate Operations CS208. Logical, Shift and Rotate Operations  A particular bit, or set of bits, within the byte can be set to 1.
Logical and Shift operations A particular bit, or set of bits, within the byte is set to 1 or 0 depending on conditions encountered during the execution.
Level ISA3: Information Representation
Signed Numbers.
Floating Point Numbers
Binary Math CS208. Decimal Addition Example ) Add = 15 Write down 5, carry ) Add = 8 Write down 8 3)
Decimal Addition What is going on? (carry) (subtract the base)
Introduction to Computer Engineering by Richard E. Haskell Shift and Rotate Instructions Module M16.2 Section 10.3.
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.
FIGURES FOR CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
Operations on data CHAPTER 4.
4 Operations On Data Foundations of Computer Science ã Cengage Learning.
Numbering systems.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Binary Arithmetic Stephen Boyd March 14, Two's Complement Most significant bit represents sign. 0 = positive 1 = negative Positive numbers behave.
Chapter 7 Arithmetic Operations and Circuits Binary Arithmetic Addition –When the sum exceeds 1, carry a 1 over to the next-more-significant column.
©zaher elsir Sudan Academy for Banking & Financial Sciences Decimal Number System Base (Radix)10 Digits0, 1, 2, 3, 4, 5, 6, 7, 8, 9 e.g The magnitude.
Khaled A. Al-Utaibi  Introduction  Arithmetic Instructions  Basic Logical Instructions  Shift Instructions  Rotate Instructions.
1 Homework Turn in HW2 tonight HW3 is on-line already Questions?
10-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept Representing Information in Computers:  numbers: counting numbers,
IT101: INFORMATION TECHNOLOGY FUNDAMENTALS 1 Edited By Dr. Ahmed Abo-Bakr Information Technology Dept. Faculty of Computers & Information.
1 Week 2: Binary, Octal and Hexadecimal Numbers READING: Chapter 2.
Operations on Bits Arithmetic Operations Logic Operations
Lecture12. Outline Binary representation of integer numbers Operations on bits –The Bitwise AND Operator –The Bitwise Inclusive-OR Operator –The Bitwise.
Computer Math CPS120 Introduction to Computer Science Lecture 4.
AEEE2031 Data Representation and Numbering Systems.
1 Arithmetic and Logic Operations Patt and Patel Ch. 2 & 3.
Chapter 7 Section 7.2 Addition & Subtraction in Different Bases.
Data Representation in Computer Systems. 2 Signed Integer Representation The conversions we have so far presented have involved only positive numbers.
07/12/ Data Representation Two’s Complement & Binary Arithmetic.
Addition and Substraction
Outline Binary Addition 2’s complement Binary Subtraction Half Adder
1 4. Computer Maths and Logic 4.1 Number Systems.
Introduction To Number Systems Binary System M. AL-Towaileb1.
WEEK 4 ET2640 Logic and Numerical Methods 1ET2640.
Chapter 7 Bit Manipulation. 7.1 Logical Operations.
©2010 Cengage Learning SLIDES FOR CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION Click the mouse to move to the next page. Use the ESC key to exit.
CPS120: Introduction to Computer Science Computer Math: Addition and Subtraction.
Chapter 4 Operations on Bits. Apply arithmetic operations on bits when the integer is represented in two’s complement. Apply logical operations on bits.
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
Microprocessor & Assembly Language
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
COMPUTER ORGANIZATION 4 TH LECTURE. ASCII Code  ASCII ( American Standard Code for Information Interchange).  Input and output devices that communicate.
Chapter 4 Operations on Bits.
Boolean Algebra, Bitwise Operations
Data Representation in Computer Systems
Addition and Substraction
King Fahd University of Petroleum and Minerals
Shift & Rotate Instructions)
Unit 18: Computational Thinking
Shift & Rotate Instructions)
CPS120: Introduction to Computer Science
§4.3, Computation in Positional Systems
Computer Organization and Assembly Language
Chapter3 Fixed Point Representation
Introduction To Number Systems
靜夜思 床前明月光, 疑是地上霜。 舉頭望明月, 低頭思故鄉。 ~ 李白 李商隱.
Shift and Rotate Instructions.
CS-401 Computer Architecture & Assembly Language Programming
Ch. 5 – Intel 8086 – study details from Yu & Marut
Two’s Complement & Binary Arithmetic
Presentation transcript:

Binary Operations Math/Logical

Binary Math

Decimal Addition Example ) Add = 15 Write down 5, carry ) Add = 8 Write down 8 3) Add = 14 Write down 4, carry 1 2) Add = 11 Write down 1, carry 1 Add 3758 to 4657:

Decimal Addition Explanation What just happened? (carry) (sum) (subtract the base) So when the sum of a column is equal to or greater than the base, we subtract the base from the sum, record the difference, and carry one to the next column to the left.

Binary Addition Rules Rules: = = = 1(just like in decimal) 1 + 1= 2 10 = 10 2 = 0 with 1 to carry = 3 10 = 11 2 = 1 with 1 to carry

Binary Addition Example Example 1: Add binary to Col 1) Add = 1 Write 1 Col 2) Add = 1 Write 1 Col 3) Add = 2 (10 in binary) Write 0, carry 1 Col 4) Add = 2 Write 0, carry 1 Col 6) Add = 2 Write 0, carry 1 Col 5) Add = 3 (11 in binary) Write 1, carry 1 Col 7) Bring down the carried 1 Write 1

Binary Addition Explanation In the first two columns, there were no carries. In column 3, we add = 2 Since 2 is equal to the base, subtract the base from the sum and carry 1. In column 4, we also subtract the base from the sum and carry 1. In column 6, we also subtract the base from the sum and carry 1. In column 5, we also subtract the base from the sum and carry 1. In column 7, we just bring down the carried What is actually happened when we carried in binary?

Binary Addition Verification Verification  = = You can always check your answer by converting the figures to decimal, doing the addition, and comparing the answers.

Binary Addition Example 2 Verification  = = Example 2: Add 1111 to

Decimal Subtraction Example Subtract 4657 from 8025: )Try to subtract 5 – 7  can’t. Must borrow 10 from next column. 4) Subtract 7 – 4 = 3 3) Subtract 9 – 6 = 3 2)Try to subtract 1 – 5  can’t. Must borrow 10 from next column. But next column is 0, so must go to column after next to borrow. Add the borrowed 10 to the original 0. Now you can borrow 10 from this column. Add the borrowed 10 to the original 5. Then subtract 15 – 7 = 8. Add the borrowed 10 to the original 1.. Then subract 11 – 5 = 6

Decimal Subtraction Explanation  So when you cannot subtract, you borrow from the column to the left.  The amount borrowed is 1 base unit, which in decimal is 10.  The 10 is added to the original column value, so you will be able to subtract

Binary Subtraction Explanation  In binary, the base unit is 2  So when you cannot subtract, you borrow from the column to the left.  The amount borrowed is 2.  The 2 is added to the original column value, so you will be able to subtract.

Binary Subtraction Example Example 1: Subtract binary from Col 1) Subtract 1 – 0 = 1 Col 5) Try to subtract 0 – 1  can’t. Must borrow from next column. Col 4) Subtract 1 – 1 = 0 Col 3) Try to subtract 0 – 1  can’t. Must borrow 2 from next column. But next column is 0, so must go to column after next to borrow. Add the borrowed 2 to the 0 on the right. Now you can borrow from this column (leaving 1 remaining). Col 2) Subtract 1 – 0 = 1 Add the borrowed 2 to the original 0. Then subtract 2 – 1 = 1 1 Add the borrowed 2 to the remaining 0. Then subtract 2 – 1 = 1 Col 6) Remaining leading 0 can be ignored.

Binary Subtraction Verification Verification  = = Subtract binary from :

Binary Subtraction Example Example 2: Subtract binary from Verification  = = 21 10

Logical, Shift, and Rotate Operations

Logical, Shift and Rotate Operations  A particular bit, or set of bits, within the byte can be set to 1 or 0, depending on conditions encountered during the execution of a program.  When so used, these bits are often called "flags".  Frequently, the programmer must manipulate these individual bits - an activity sometimes known as "bit twiddling".  The logical, shift, and rotate operations provide the means for manipulating the bits.

Logical OR Rules OR Operations OR Results in 1 if either or both of the operands are 1. OR Table 0 OR 0 = 0 0 OR 1 = 1 1 OR 0 = 1 1 OR 1 = 1

Logical OR Operation To perform the OR operation, take one column at a time and perform the OR operation using the OR table. Ex 1: OR

Logical OR Examples Ex 3: OR Ex 2: OR

Logical XOR Rules XOR Operations The exclusive OR. Similar to OR except that it now gives 0 when both its operands are 1. Rules. 0 XOR 0 = 0 0 XOR 1 = 1 1 XOR 0 = 1 1 XOR 1 = 0

Logical XOR Examples Ex 1: XOR Ex 2: XOR

Logical AND Rules AND Operations AND yields 1 only if both its operands are 1. Rules. 0 AND 0 = 0 0 AND 1 = 0 1 AND 0 = 0 1 AND 1 = 1

Logical AND Examples Ex 1: AND Ex 2: AND

Logical NOT NOT Operations NOT is a separate operator for flipping the bits. Rules. NOT 0 = 1 NOT 1 = 0 Example.NOT =

Shift and Rotate operations Whereas logical operations allow the changing of bit values in place, SHIFT and ROTATE operations allow bits to be moved left or right without changing their values.

Shift Left operation SHL SHL (shift left) shifts each bit one place to the left. The original leftmost bit is lost and a 0 is shifted into the rightmost position. Ex 1.SHL Ex 2.SHL = =

Shift Left - Multiple Bits SHL # bits means to shift left # times Ex 1: SHL Ex 2: SHL = =

Shift Right operation SHR SHR (shift right) shifts each bit one place to the right. The original rightmost bit is lost and a 0 is shifted into the leftmost position. Ex 1.SHR Ex 2.SHR = =

Shift Right – Multiple Bits SHR # bits means to shift right # times Ex 1: SHR = Ex 2: SHR =

Arithmetic Shift Right operation ASR (retains rightmost sign bit) Shifts each bit one place to the right. The original rightmost bit is lost and a the value of the most significant bit (leftmost bit) is shifted into the new leftmost position. Ex 1.ASR Ex 2.ASR = =

Arithmetic Shift Right – Multiple Bits ASR # bits means to arithmetic shift right # times Ex 1: ASR = Ex 2: ASR =

Rotate Left operation ROL ROL (rotate left) shifts each bit one place to the left. The original leftmost bit is shifted into the rightmost position. No bits are lost. Ex 1.ROL Ex 2. ROL =

Rotate Left – Multiple Bits ROL # bits means to rotate left # times Ex 1: ROL = Ex 2: ROL =

Rotate Right operation ROR ROR (rotate right) shifts each bit one place to the right. The original rightmost bit is shifted into the leftmost position. No bits are lost. Ex 1.ROR Ex 2.ROR =

Rotate Right – Multiple Bits ROR # bits means to rotate right # times Ex 1: ROR = Ex 2: ROR =