©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.

Slides:



Advertisements
Similar presentations
©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.
Advertisements

COE 202: Digital Logic Design Signed Numbers
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3: IT Students.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Major Numeric Data Types Unsigned Integers Signed Integer Alphanumeric Data – ASCII & UNICODE Floating Point Numbers.
Assembly Language and Computer Architecture Using C++ and Java
Chapter 4 Operations on Bits
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 =
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.
Number Representation Rizwan Rehman, CCS, DU. Convert a number from decimal to binary notation and vice versa. Understand the different representations.
Operations on data CHAPTER 4.
4 Operations On Data Foundations of Computer Science ã Cengage Learning.
Chapter 3 Data Representation part2 Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
Chapter3 Fixed Point Representation Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
The Binary Number System
Chapter 4 Operations on Bits. Apply arithmetic operations on bits when the integer is represented in two’s complement. Apply logical operations on bits.
Chapter 3 Number Representation. Convert a number from decimal 、 hexadecimal,octal to binary notation and vice versa. Understand the different representations.
Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways:  Fixed-point  Floating-point.
Computer Arithmetic Nizamettin AYDIN
MICRO OPERATIONS Department of Computer Engineering, M.S.P.V.L. Polytechnic College, Pavoorchatram.
Chapter 2 Data and Number Representations
NUMBER REPRESENTATION CHAPTER 3 – part 3. ONE’S COMPLEMENT REPRESENTATION CHAPTER 3 – part 3.
Chapter 1 Data Storage(3) Yonsei University 1 st Semester, 2015 Sanghyun Park.
9.4 FLOATING-POINT REPRESENTATION
Foundations of Computer Science Chapter 4 Operations on Bits.
ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations.
Computer Arithmetic and the Arithmetic Unit Lesson 2 - Ioan Despi.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Chapter 3 Number Representation. Convert a number from decimal to binary notation and vice versa. Understand the different representations of an integer.
Positional Number Systems
Number Representation
Operations on Bits Arithmetic Operations Logic Operations
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Number Systems Revision of conversations What is a register Addition Complementation.
Floating Point Arithmetic
07/12/ Data Representation Two’s Complement & Binary Arithmetic.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
Arithmetic Operations
Chapter 4 Operations on Bits. Apply arithmetic operations on bits when the integer is represented in two’s complement. Apply logical operations on bits.
Number Representation and Arithmetic Circuits
©Brooks/Cole, 2003 Chapter 3 Number Representation.
1 Ethics of Computing MONT 113G, Spring 2012 Session 4 Binary Addition.
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.
Computer Organization 1 Data Representation Negative Integers.
Lecture No. 4 Computer Logic Design. Negative Number Representation 3 Options –Sign-magnitude –One’s Complement –Two’s Complement  used in computers.
{ Binary “There are 10 types of people in the world: Those who understand binary, and those who don't.”
Materials on the Exam Introduction Data Representation in Computer Systems Boolean Algebra Digital Logic MARIE: An Introduction to a Simple Computer Until.
Software Design and Development Storing Data Computing Science.
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
David Kauchak CS 52 – Spring 2017
A brief comparison of integer and double representation
Chapter 4 Operations on Bits.
A Level Computing Component 2
Data Representation Data Types Complements Fixed Point Representation
Teaching Computing to GCSE
Number Representation
Chapter3 Fixed Point Representation
GCSE COMPUTER SCIENCE Topic 3 - Data 3.3 Logical and Arithmetic Shifts.
Chapter 1 (Part c) Digital Systems and Binary Numbers
OBJECTIVES After reading this chapter, the reader should be able to :
靜夜思 床前明月光, 疑是地上霜。 舉頭望明月, 低頭思故鄉。 ~ 李白 李商隱.
1.6) Storing Integer: 1.7) storing fraction:
Two’s Complement & Binary Arithmetic
Presentation transcript:

©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. Apply logical operations on bits. Understand the applications of logical operations using masks. After reading this chapter, the reader should be able to: O BJECTIVES Understand the shift operations on numbers and how a number can be multiplied or divided by powers of two using shift operations.

©Brooks/Cole, 2003 Figure 4-1 Operations on bits

©Brooks/Cole, 2003 ARITHMETICOPERATIONSARITHMETICOPERATIONS 4.1

Arithmetic operations Arithmetic operations involve: Adding (+) Subtracting (--) Multiplying (X) Dividing (/) And so on…

©Brooks/Cole, 2003 Table 4.1 Adding bits Number of 1s Number of 1s None One Two Three Result Result Carry Carry Addition in two’s complement

©Brooks/Cole, 2003 Rule of Adding Integers in Two’s Complement Add 2 bits and propagate the carry to the next column. If there is a final carry after the leftmost column addition, discard ( 捨棄 ) it. Note:

©Brooks/Cole, 2003 Example 1 Add two numbers in two’s complement representation: (+17) + (+22)  (+39) Solution Carry Result  39

©Brooks/Cole, 2003 Example 2 Add two numbers in two’s complement representation: (+24) + (-17)  (+7) Solution Carry Result  +7

©Brooks/Cole, 2003 Example 3 Add two numbers in two’s complement representation: (-35) + (+20)  (-15) Solution Carry Result  -15

©Brooks/Cole, 2003 Example 4 Add two numbers in two’s complement representation: (+127) + (+3)  (+130) Solution Carry (Error) An overflow has occurred Result  -126 (Error) An overflow has occurred.

©Brooks/Cole, 2003 Range of numbers in two’s complement representation - (2 N-1 ) (2 N-1 –1) Note:

©Brooks/Cole, 2003 Figure 4-2 Two’s complement numbers visualization

©Brooks/Cole, 2003 When you do arithmetic operations on numbers in a computer, remember that each number and the result should be in the range defined by the bit allocation. Note:

©Brooks/Cole, 2003 Example 5 Subtract 62 from 101 in two’s complement: (+101) - (+62)  (+101) + (-62) Solution Carry Result  39 The leftmost carry is discarded. Subtraction in two’s complement

©Brooks/Cole, 2003 Arithmetic operations on floating-point numbers Addition and subtraction for floating-point numbers are one process. (p. 54) Check the sign. (a, b) Move the decimal points to make the exponents the same. Add or subtract the mantissas ( 底數 ). Normalize the result before storing in memory. Check for any overflow.

©Brooks/Cole, 2003 Example 6 Add two floats: Solution The exponents are 5 and 3. The numbers are: +2 5 x and +2 3 x Make the exponents the same. (+2 5 x )+ (+2 5 x )  +2 5 x After normalization +2 6 x , which is stored as: Addition

©Brooks/Cole, 2003 LOGICALOPERATIONSLOGICALOPERATIONS 4.2

Logical operations A logical operation can accept 1 or 2 bits to create only 1 bit. Unary operation (Figure4.3) Binary operation (Figure4.3)

©Brooks/Cole, 2003 Figure 4-3 Unary and binary operations

©Brooks/Cole, 2003 Figure 4-4 Logical operations

©Brooks/Cole, 2003 Figure 4-5 Truth tables

©Brooks/Cole, 2003 Figure 4-6 Unary operator -- NOT operator

©Brooks/Cole, 2003 Example 7 Use the NOT operator on the bit pattern Solution Target NOT Result NOT operator

©Brooks/Cole, 2003 Figure 4-7 Binary operator--AND operator

©Brooks/Cole, 2003 Example 8 Use the AND operator on bit patterns and Solution Target AND Result AND operator

©Brooks/Cole, 2003 Figure 4-8 Inherent ( 本質的 ) rule of the AND operator

©Brooks/Cole, 2003 Figure 4-9 Binary operator--OR operator

©Brooks/Cole, 2003 Example 9 Use the OR operator on bit patterns and Solution Target OR Result OR operator

©Brooks/Cole, 2003 Figure 4-10 Inherent rule of the OR operator

©Brooks/Cole, 2003 Figure 4-11 Binary operator--XOR operator

©Brooks/Cole, 2003 Example 10 Use the XOR operator on bit patterns and Solution Target XOR Result XOR operator

©Brooks/Cole, 2003 Figure 4-12 Inherent rule of the XOR operator

©Brooks/Cole, 2003 Figure 4-13 Mask ( 遮罩 ) Applications

©Brooks/Cole, 2003 Figure 4-14 Example of unsetting specific bits

©Brooks/Cole, 2003 Example 11 Use a mask to unset (clear) the 5 leftmost bits of a pattern. Test the mask with the pattern Solution The mask is Target AND Mask Result

©Brooks/Cole, 2003 Example 12 Imagine a power plant ( 水力發電廠 ) that pumps water ( 供水 ) to a city using eight pumps ( 抽水機 ). The state of the pumps (on or off) can be represented by an 8-bit pattern. For example, the pattern shows that pumps 1 to 3 (from the right), 7 and 8 are on while pumps 4, 5, and 6 are off. Now assume pump 7 shuts down. How can a mask show this situation? Solution on the next slide.

©Brooks/Cole, 2003 Use the mask to AND with the target pattern. The only 0 bit (bit 7) in the mask turns off the seventh bit in the target. Target AND Mask Result Solution

©Brooks/Cole, 2003 Figure 4-15 Example of setting specific bits

©Brooks/Cole, 2003 Example 13 Use a mask to set the 5 leftmost bits of a pattern. Test the mask with the pattern Solution The mask is Target OR Mask Result

©Brooks/Cole, 2003 Example 14 Using the power plant example, how can you use a mask to to show that pump 6 is now turned on? Solution Use the mask Target OR Mask Result

©Brooks/Cole, 2003 Figure 4-16 Example of flipping ( 跳動的 ) specific bits

©Brooks/Cole, 2003 Example 15 Use a mask to flip the 5 leftmost bits of a pattern. Test the mask with the pattern Solution Target XOR Mask Result

©Brooks/Cole, 2003 SHIFTOPERATIONSSHIFTOPERATIONS 4.3

Figure 4-17 Shift operations Right shift Left shift

©Brooks/Cole, 2003 Solution If a bit pattern represents an unsigned number, a right-shift operation divides the number by two. The pattern represents 59. When you shift the number to the right, you get , which is 29. If you shift the original number to the left, you get , which is 118. Example 16 Show how you can divide or multiply a number by 2 using shift operations.

©Brooks/Cole, 2003 Example 17 Use the mask to AND with the target to keep the fourth bit and clear the rest of the bits. Solution Use a combination of logical and shift operations to find the value (0 or 1) of the fourth bit (from the right). Continued on the next slide

©Brooks/Cole, 2003 Solution (continued) Target a b c d e f g h AND Mask Result e Shift the new pattern three times to the right 0000e000  00000e00  e0  e Now it is easy to test the value of the new pattern as an unsigned integer. If the value is 1, the original bit was 1; otherwise the original bit was 0.

©Brooks/Cole, 2003 Key terms AND operator Arithmetic operation Binary operation Binary operator Carry Clear Flip Floating-point number Force ( 強迫 ) to 0 Force ( 強迫 ) to 1 Logical operation Mantissa Mask NOT operator OR operator Overflow Set Truth table Two’s complement Unary operation Unary operator Unset XOR operator