1 a historical perspective 91 circuit technology at

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: operations not including right shifts or division. Function sra performs an arithmetic right shift using a logical right shift (given by value xsrl), followed by other operations not including right shifts or division. You may assume that int’s are 32-bits long. The shift amount k can range from 0 to 31. unsigned srl(unsigned x, int k) { /* Perform shift arithmetically */ unsigned xsra = (int) x >> k; /* ... */ } int sra(int x, int k) { /* Perform shift logically */ int xsrl = (unsigned) x >> k; 2.5. SUMMARY 85 /* ... */ } Homework Problem 2.45 [Category 2]: Assume we are running code on a 32-bit machine using two’s complement arithmetic for signed variables. The variables are declared and initialized as follows: int x = foo(); int y = bar(); unsigned ux = x; unsigned uy = y; /* Arbitrary value */ /* Arbitrary value */ For each of the following C expressions, either (1) argue that it is true (i.e., evaluates to 1) for all values of x and y, or (2) give example values of x and y for which it is false (i.e., evaluates to 0.) A. (x >= 0) || ((2*x) <...
View Full Document

Ask a homework question - tutors are online