Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

Similar documents
Chapter 4. Operations on Data

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

104 - Introduction to Computer Science - Midterm Exam

Introduction to Computer Science-103. Midterm

Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers

FLOATING POINT NUMBERS

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as:

Divide: Paper & Pencil

COMP Overview of Tutorial #2

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two Solutions 26 February 2014

COMP2611: Computer Organization. Data Representation

Floating Point. The World is Not Just Integers. Programming languages support numbers with fraction

Floating Point Arithmetic

CS101 Lecture 04: Binary Arithmetic

Computer Arithmetic Floating Point

Floating-point Arithmetic. where you sum up the integer to the left of the decimal point and the fraction to the right.

Time: 8:30-10:00 pm (Arrive at 8:15 pm) Location What to bring:

Floating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Lecture 3

Floating-point representations

Floating-point representations

Chapter 3: Arithmetic for Computers

±M R ±E, S M CHARACTERISTIC MANTISSA 1 k j

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

Introduction to Computers and Programming. Numeric Values

Floating Point Arithmetic


Chapter 3: part 3 Binary Subtraction

CS & IT Conversions. Magnitude 10,000 1,

Numerical Representations On The Computer: Negative And Rational Numbers

ECE232: Hardware Organization and Design

Chapter 2 Data Representations

Numerical Representations On The Computer: Negative And Rational Numbers

CHAPTER 5: Representing Numerical Data

unused unused unused unused unused unused

Data Representations & Arithmetic Operations

Module 2: Computer Arithmetic

CS 101: Computer Programming and Utilization

Number Systems. Both numbers are positive

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

C NUMERIC FORMATS. Overview. IEEE Single-Precision Floating-point Data Format. Figure C-0. Table C-0. Listing C-0.

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

CSE 140 Homework One

Binary Addition & Subtraction. Unsigned and Sign & Magnitude numbers

Adding Binary Integers. Part 5. Adding Base 10 Numbers. Adding 2's Complement. Adding Binary Example = 10. Arithmetic Logic Unit

ECE 2030B 1:00pm Computer Engineering Spring problems, 5 pages Exam Two 10 March 2010

A Level Computing. Contents. For the Exam:

3.5 Floating Point: Overview

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

UNIT 7A Data Representation: Numbers and Text. Digital Data

Timing for Ripple Carry Adder

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

COMPUTER ARCHITECTURE AND ORGANIZATION. Operation Add Magnitudes Subtract Magnitudes (+A) + ( B) + (A B) (B A) + (A B)

Signed Binary Numbers

UNIT-III COMPUTER ARTHIMETIC

Number Systems and Computer Arithmetic

MYcsvtu Notes DATA REPRESENTATION. Data Types. Complements. Fixed Point Representations. Floating Point Representations. Other Binary Codes

Co-processor Math Processor. Richa Upadhyay Prabhu. NMIMS s MPSTME February 9, 2016

CO212 Lecture 10: Arithmetic & Logical Unit

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

Floating Point Numbers

Floating Point Numbers

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

Numeric Encodings Prof. James L. Frankel Harvard University

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

VTU NOTES QUESTION PAPERS NEWS RESULTS FORUMS Arithmetic (a) The four possible cases Carry (b) Truth table x y

1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM

The ALU consists of combinational logic. Processes all data in the CPU. ALL von Neuman machines have an ALU loop.

Foundations of Computer Systems

Chapter Three. Arithmetic

COMP 122/L Lecture 2. Kyle Dewey

MACHINE LEVEL REPRESENTATION OF DATA

The Sign consists of a single bit. If this bit is '1', then the number is negative. If this bit is '0', then the number is positive.

Computer Arithmetic Ch 8

Computer Arithmetic Ch 8

CHW 261: Logic Design

Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC

Time (self-scheduled): Location Schedule Your Exam: What to bring:

IT 1204 Section 2.0. Data Representation and Arithmetic. 2009, University of Colombo School of Computing 1

Chapter 5 : Computer Arithmetic

FLOATING POINT NUMBERS

Inf2C - Computer Systems Lecture 2 Data Representation

1.2 Round-off Errors and Computer Arithmetic

Basic Definition INTEGER DATA. Unsigned Binary and Binary-Coded Decimal. BCD: Binary-Coded Decimal

Module 12 Floating-Point Considerations

Floating Point (with contributions from Dr. Bin Ren, William & Mary Computer Science)

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

Digital Fundamentals

CS321. Introduction to Numerical Methods

9/3/2015. Data Representation II. 2.4 Signed Integer Representation. 2.4 Signed Integer Representation

Computer System and programming in C

CSC201, SECTION 002, Fall 2000: Homework Assignment #2

Introduction to Computer Science. Homework 1

Arithmetic Logic Unit

Floating Point Numbers

VHDL implementation of 32-bit floating point unit (FPU)

Signed Multiplication Multiply the positives Negate result if signs of operand are different

Chapter 3. Information Representation

1/31/2017. Expressions are Used to Perform Calculations. ECE 120: Introduction to Computing. Five Arithmetic Operators on Numeric Types

Representing numbers on the computer. Computer memory/processors consist of items that exist in one of two possible states (binary states).

Transcription:

CHAPTER 4 Operations On Data (Solutions to Odd-Numbered Problems) Review Questions 1. Arithmetic operations interpret bit patterns as numbers. Logical operations interpret each bit as a logical values (true or false). 3. The bit allocation can be 1. In this case, the data type normally represents a logical value. 5. The decimal point of the number with the smaller exponent is shifted to the left until the exponents are equal. 7. The common logical binary operations are: AND, OR, and XOR. 9. The NOT operation inverts logical values (bits): it changes true to false and false to true. 11. The result of an OR operation is true when one or both of the operands are true. 13. An important property of the AND operator is that if one of the operands is false, the result is false. 15. An important property of the XOR operator is that if one of the operands is true, the result will be the inverse of the other operand. 17. The AND operator can be used to clear bits. Set the desired positions in the mask to 0. 19. The logical shift operation is applied to a pattern that does not represent a signed number. The arithmetic shift operation assumes that the bit pattern is a signed number in two s complement format. 1

2 Multiple-Choice Questions 21. d 23. c 25. b 27. b 29. c 31. c 33. c 35. a 37. c 39. b Exercises 41. a. (99) 16 AND (99) 16 = (10011001) 2 AND (10011001) 2 = (10011001) 2 = (99) 16 b. (99) 16 AND (00) 16 = (10011001) 2 AND (00000000) 2 = 00000000) 2 = (00) 16 c. (99) 16 AND (FF) 16 = (10011001) 2 AND (11111111) 2 = (10011001) 2 = (99) 16 d. (99) 16 AND (FF) 16 = (11111111) 2 AND (11111111) 2 = (11111111) 2 = (FF) 16 43. 45. 47. a. b. c. d. NOT[(99) 16 OR (99)1 6 ] = NOT [(10011001) 2 OR (10011001) 2 ] = (01100110) 2 = (66) 16 (99) 16 OR [NOT (00) 16 ] = (10011001) 2 OR [NOT (00000000) 2 ] = (10011001) 2 OR (11111111) 2 = (11111111) 2 = (FF) 16 [(99) 16 AND (33) 16 ] OR [(00) 16 AND (FF) 16 ) = [(10011001) 2 AND (00110011) 2 ] OR [(00000000) 2 AND (11111111) 2 ] = (00010001) 2 OR (00000000) 2 = (00010001) 2 = (11) 16 [(99) 16 OR (33) 16 ] AND [(00) 16 OR (FF) 16 ] = [(10011001) 2 OR (00110011) 2 ] AND [(00000000) 2 OR (11111111) 2 ] = (10111011) 2 AND (11111111) 2 = (10111011) 2 = (BB) 16 Mask = (00001111) 2 Operation: Mask OR (xxxxxxxx) 2 = (xxxx1111) 2 Mask1= (00011111) 2 Mask2 = (00000011) 2 Operation: [Mask1 AND (xxxxxxxx) 2 ] OR Mask2 = (000xxx11) 2 49. Arithmetic left shift multiplies an integer by 2. To multiply an integer by 8, we apply the arithmetic left shift operation three times.

3 51. a. 00010011 + 00010111 1 1 1 1 Carry Decimal 0 0 0 1 0 0 1 1 19 + 0 0 0 1 0 1 1 1 23 0 0 1 0 1 0 1 0 42 b. 00010011 00010111 = 000010011 + ( 00010111) = 00010011 + 11101001 = 1 1 Carry Decimal 0 0 0 1 0 0 1 1 19 + 1 1 1 0 1 0 0 1 23 1 1 1 1 1 1 0 0 4 c. ( 00010011) + 00010111 = 11101101 + 00010111 1 1 1 1 1 1 1 1 Carry Decimal 1 1 1 0 1 1 0 1 19 + 0 0 0 1 0 1 1 1 23 0 0 0 0 0 1 0 0 4 d. ( 00010011) 00010111 = ( 00010011) + ( 00010111) = 11101101 + 11101001 = 53. Addition of two integers does not create overflow if the result is in the range ( 128 to +127). a. Addition does not create overflow because ( 62) + (+63) = 1 (in the range). b. Addition does not create overflow because (+2) + (+63) = 65 (in the range). c. Addition does not create overflow because ( 62) + ( 1) = 63 (in the range). d. Addition does not create overflow because (+2) + ( 1) = 1 (in the range). 55. a. 1 1 1 1 1 Carry Decimal 1 1 1 0 1 1 0 1 19 + 1 1 1 0 1 0 0 1 23 1 1 0 1 0 1 1 0 42 1 1 1 1 Carry Hexadecimal 0 0 0 0 0 0 0 1 0 0 1 0 1 0 1 0 012A + 0 0 0 0 1 1 1 0 0 0 1 0 0 1 1 1 0E27 0 0 0 0 1 1 1 1 0 1 0 1 0 0 0 1 0F51

4 b. c. d. 1 1 1 1 Carry Hexadecimal 0 1 1 1 0 0 0 1 0 0 1 0 1 0 1 0 712A + 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 9E00 0 0 0 0 1 1 1 1 0 0 1 0 1 0 1 0 10F2A Note that the result is not valid because of overflow. 1 Carry Hexadecimal 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 8011 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0001 1 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 8012 1 1 1 1 1 Carry Hexadecimal 1 1 1 0 0 0 0 1 0 0 1 0 1 0 1 0 E12A + 1 0 0 1 1 1 1 0 0 0 1 0 0 1 1 1 9E27 0 1 1 1 1 1 1 1 0 1 0 1 0 0 0 1 17F51 57. Note that the result is not valid because of overflow a. 34.75 + 23.125 = (100010.11) 2 + (10111.001) 2 = 2 5 (1.0001011) 2 + 2 4 (1.0111001) 2. These two numbers are stored in floating-point format as shown, but we need to remember that each number has a hidden 1 (which is not stored, but assumed). E 1 = 127 + 5 = 132 = (10000100) 2 and E 2 = 127 + 4 = 131 = (10000011) 2. The first few steps in UML diagram is not needed. We move to denormalization. We denormalize the numbers by adding the hidden 1 s to the mantissa and incrementing the exponent. A 0 10000100 00010110000000000000000 B 0 10000011 01110010000000000000000 Now both denormalized mantissas are 24 bits and include the hidden 1 s. They should store in a location to hold all 24 bits. Each exponent is incremented. A 0 10000101 100010110000000000000000 B 0 10000100 101110010000000000000000 We align the mantissas. We increment the second exponent by 1 and shift its mantissa to the right once. A 0 10000101 100010110000000000000000 B 0 10000101 010111001000000000000000

5 Now we do sign-and-magnitude addition treating the sign and the mantissa of each number as one integer stored in sign-and-magnitude representation. R 0 10000101 11100111100000000000000 There is no overflow in mantissa, so we normalized. R 0 10000100 1100111100000000000000 The mantissa is only 23 bits because there is no overflow, no rounding is needed. E = (10000100) 2 = 132, M = 11001111 In other words, the result is (1.11001111) 2 2 132 127 = (111001.111) 2 = 57.875 b. 12.625 + 451 = (1100.101) 2 + (111000011) 2 = 2 3 (1.100101) 2 + 2 8 (1.11000011) 2. These two numbers are stored in floating-point format as shown, but we need to remember that each number has a hidden 1 (which is not stored, but assumed). E 1 = 127 + 3 = 130 = (10000010) 2 and E 2 = 127 + 8 = 135 = (10000111) 2. A 1 10000010 10010100000000000000000 B 0 10000111 11000011000000000000000 The first few steps in UML diagram is not needed. We move to denormalization. We denormalize the numbers by adding the hidden 1 s to the mantissa and incrementing the exponent. Now both denormalized mantissas are 24 bits and include the hidden 1 s. They should store in a location to hold all 24 bits. Each exponent is incremented. A 1 10000011 110010100000000000000000 B 0 10001000 111000011000000000000000 We align the mantissas. We increment the first exponent by 5 and shift its mantissa to the right five times. A 1 10001000 000001100101000000000000 B 0 10001000 111000011000000000000000 Now we do sign-and-magnitude addition treating the sign and the mantissa of each number as one integer stored in sign-and-magnitude representation. R 0 10001000 110110110011000000000000

6 There is no overflow in mantissa, so we normalized. R 0 10000111 10110110011000000000000 The mantissa is only 23 bits because there is no overflow, no rounding is needed. E = (10000111) 2 = 135, M = 10110110011 In other words, the result is (1.10110110011) 2 2 135 127 = (110110110.011) 2 = 438.375 c. 33.1875 0.4375 = (100001.0011) 2 (0.0111) 2 = 2 5 (1.000010011) 2 2 2 (1.11) 2. These two numbers are stored in floating-point format as shown, but we need to remember that each number has a hidden 1 (which is not stored, but assumed). E 1 = 127 + 5 = 132 = (10000100) 2 and E 2 = 127 + ( 2) = 125 = (01111101) 2. A 0 10000100 00001001100000000000000 B 0 01111101 11000000000000000000000 The first two steps in UML diagram is not needed. Since the operation is subtraction, we change the sing of the second number. A 0 10000100 00001001100000000000000 B 1 01111101 11000000000000000000000 We denormalize the numbers by adding the hidden 1 s to the mantissa and incrementing the exponent. Now both denormalized mantissas are 24 bits and include the hidden 1 s. They should store in a location to hold all 24 bits. Each exponent is incremented. A 0 10000101 100001001100000000000000 B 1 01111110 111000000000000000000000 We align the mantissas. We increment the second exponent by 7 and shift its mantissa to the right seven times. A 0 10000101 100001001100000000000000 B 1 10000101 000000011100000000000000 Now we do sign-and-magnitude addition treating the sign and the mantissa of each number as one integer stored in sign-and-magnitude representation.

7 R 0 10000101 100000110000000000000000 There is no overflow in mantissa, so we normalized. R 0 10000100 00000110000000000000000 The mantissa is only 23 bits because there is no overflow, no rounding is needed. E = (10000100) 2 = 132, M = 0000011 The result is (1.0000011) 2 2 132 127 = (100000.11) 2 = 32.75 d. 344.3125 123.5625 = (101011000.0101) 2 (1111011.1001 ) 2 = 2 8 (1.010110000101) 2 2 6 (1.1110111001) 2. These two numbers are stored in floating-point format as shown, but we need to remember that each number has a hidden 1 (which is not stored, but assumed). E 1 = 127 + 8 = 135 = (10000111) 2 and E 2 = 127 + 6 = 133 = (10000101) 2. A 1 10000111 01011000010100000000000 B 0 10000101 11101110010000000000000 The first two steps in UML diagram is not needed. Since the operation is subtraction, we change the sing of the second number. A 1 10000111 01011000010100000000000 B 1 10000101 11101110010000000000000 We denormalize the numbers by adding the hidden 1 s to the mantissa and incrementing the exponent. Now both denormalized mantissas are 24 bits and include the hidden 1 s. They should store in a location to hold all 24 bits. Each exponent is incremented. A 1 10001000 101011000010100000000000 B 1 10000110 111101110010000000000000 We align the mantissas. We increment the second exponent by 7 and shift its mantissa to the right seven times. A 1 10001000 101011000010100000000000 B 1 10001000 001111011100100000000000 Now we do sign-and-magnitude addition treating the sign and the mantissa of each number as one integer stored in sign-and-magnitude representation.

8 R 1 10001000 111010011111000000000000 There is no overflow in mantissa, so we normalized. R 1 10000111 11010011111000000000000 The mantissa is only 23 bits because there is no overflow, no rounding is needed. E = (10000111) 2 = 135, M = 11010011111 The result is (1.11010011111) 2 2 135 127 = (111010011.111) 2 = 467.875 59. The result is a number with all 1 s which has the value of 0. For example, if we add number (10110101) 2 in 8-bit allocation to its one s complement (01001010) 2 we obtain Decimal equivalent 1 0 1 1 0 1 0 1 74 + 0 1 0 0 1 0 1 0 +74 1 1 1 1 1 1 1 1 0 We use this fact in the Internet checksum in Chapter 6.