9623 Words39 Pages

C HA PT ER 2
BASICS
2–1 Manipulating Rightmost Bits
Some of the formulas in this section find application in later chapters. Use the following formula to turn off the rightmost 1-bit in a word, producing 0 if none (e.g., 01011000 ⇒ 01010000): x & (x – 1) This may be used to determine if an unsigned integer is a power of 2; apply the formula followed by a 0-test on the result. Similarly, the following formula can be used to test if an unsigned integer is of the form 2 n – 1 (including 0 or all 1’s): x & (x + 1) Use the following formula to isolate the rightmost 1-bit, producing 0 if none (e.g., 01011000 ⇒ 00001000): x & (– x) Use the following formula to isolate the rightmost 0-bit, producing 0 if none (e.g., 10100111 ⇒ 00001000): ¬x &*…show more content…*

These formulas all have duals in the following sense. Read what the formula does, interchanging 1’s and 0’s in the description. Then, in the formula, replace x – 1 with x + 1 , x + 1 with x – 1 , – x with ¬( x + 1 ) , & with |, and | with &. Leave x and ¬ x alone. Then the result is a valid description and formula. For example, the dual of the first formula in this section reads as follows: Use the following formula to turn on the rightmost 0-bit in a word, producing all 1’s if none (e.g., 10100111 ⇒ 10101111): x | (x + 1) There is a simple test to determine whether or not a given function can be implemented with a sequence of add’s, subtract’s, and’s, or’s, and not’s [War]. We may, of course, expand the list with other instructions that can be composed from*…show more content…*

Below we show branch-free expressions to evaluate the result into the sign position. To produce the 1/0 value used by some languages (e.g., C), follow the code with a shift right of 31. To produce the – 1 ⁄ 0 result used by some other languages (e.g., Basic), follow the code with a shift right signed of 31. These formulas are, of course, not of interest on machines such as MIPS, the Compaq Alpha, and our model RISC, which have comparison instructions that compute many of these predicates directly, placing a 0/1-valued result in a general purpose register. A machine instruction that computes the negative of the absolute value is handy here. We show this function as “nabs.” Unlike absolute value, it is well defined in that it never overflows. Machines that do not have “nabs” but have the more usual “abs” may use – abs(x) for nabs(x). If x is the maximum negative number, this overflows twice, but the result is correct. (We assume that the absolute value and the negation of the maximum negative number is itself.) Because some machines have neither “abs” nor “nabs,” we give an alternative that does not use them. The “nlz” function is the number of leading 0’s in its argument. The “doz” function (difference or zero) is described on page

These formulas all have duals in the following sense. Read what the formula does, interchanging 1’s and 0’s in the description. Then, in the formula, replace x – 1 with x + 1 , x + 1 with x – 1 , – x with ¬( x + 1 ) , & with |, and | with &. Leave x and ¬ x alone. Then the result is a valid description and formula. For example, the dual of the first formula in this section reads as follows: Use the following formula to turn on the rightmost 0-bit in a word, producing all 1’s if none (e.g., 10100111 ⇒ 10101111): x | (x + 1) There is a simple test to determine whether or not a given function can be implemented with a sequence of add’s, subtract’s, and’s, or’s, and not’s [War]. We may, of course, expand the list with other instructions that can be composed from

Below we show branch-free expressions to evaluate the result into the sign position. To produce the 1/0 value used by some languages (e.g., C), follow the code with a shift right of 31. To produce the – 1 ⁄ 0 result used by some other languages (e.g., Basic), follow the code with a shift right signed of 31. These formulas are, of course, not of interest on machines such as MIPS, the Compaq Alpha, and our model RISC, which have comparison instructions that compute many of these predicates directly, placing a 0/1-valued result in a general purpose register. A machine instruction that computes the negative of the absolute value is handy here. We show this function as “nabs.” Unlike absolute value, it is well defined in that it never overflows. Machines that do not have “nabs” but have the more usual “abs” may use – abs(x) for nabs(x). If x is the maximum negative number, this overflows twice, but the result is correct. (We assume that the absolute value and the negation of the maximum negative number is itself.) Because some machines have neither “abs” nor “nabs,” we give an alternative that does not use them. The “nlz” function is the number of leading 0’s in its argument. The “doz” function (difference or zero) is described on page

Related

## Algorithm Workbench Essay

330 Words | 2 Pagesdue = downpayment – total 10. Write a pseudocode statement that multiplies the variable subtotal by 0.15 and assigns the result to the variable totalfee. First you must make the variables real numbers. example.Dim subtotal As Double = 0 The statement asked for in the question will appear as totalfee = subtotal *

## Inro to Pc Programming Unit 5 Assignment 1 Homework

1059 Words | 5 PagesUnit 5 Assignment 1: Homework Short Answer 1-7 p.158 1) Explain what is meant by the term “conditionally executed”. Conditionally executed is called a single alternative decision structure because it provides only one alternative path of execution. The action is conditionally executed because it is performed only when a certain condition is true. 2) You need to test a condition and then execute one set of statements if the condition is true. If the condition is false, you need to execute a different set of statements.

## Math 471 Week 1 Case Study

1035 Words | 5 Pages(b): by reasoning from scratch. SOLUTION: We break up bit strings of length n into two cases: • Bit strings beginning with 1: There are un−1 ways to ﬁnish such a string such that there are no two consecutive

## Pt1420 Unit 2 Research Assignment 1 Researching Variable Naming Rules

386 Words | 2 PagesThere are some reserved words, which you cannot use as a variable name because Python uses them for other things. What are the variable naming rules for Java? The variable naming rules for Java is all variable names must begin with a letter of the alphabet, an underscore, or (_), or a dollar sign ($). The convention is to always use a letter of the alphabet. The dollar sign and the underscore are discouraged.

## Math Test Bus2023

2716 Words | 11 Pages2.12 b. 1.734 c. -1.740 d. 1.740 ANSWER: d -same process but now go to one tailed α=0.05 and dof = 17 4. Read the t statistic from the table of t distributions and circle the correct answer. A one-tailed test (lower tail), a sample size of 10 at a .10 level of significance; t = a. 1.383 b.

## It/210 Week 6 Assignment

399 Words | 2 PagesAssociate Program Material Appendix K Currency Conversion Peer Review Design Inspection Report |Programmer’s Name: |Brandon | |Date of Inspection |4/1/2012 | |Inspector’s Name: |Brandon | Use the following criteria to evaluate the Currency Conversion Test Procedure. If the answer to the item question is yes, place an X next to that item under the Yes column. If the answer is no, add details next to that item under the Comments column. | |Yes |Item |Comments | | |X |Is the problem description clear, concise, and accurate? | | | |X |Are the inputs to the program identified?

## Nt1210 Lab 1.1

695 Words | 3 PagesDetermine the result of 100100002+11011102. Show the mapping that you created to solve this addition problem. = 11111110 2. Determine the result of 110011002 AND 111111002. Show the mapping or truth table that you used to solve this logic problem.

## Nt1310 Unit 8 Regression Analysis

1629 Words | 7 PagesWe can conclude that the data are Poisson distributed. Chi-Square test of independence Problem 12.12 Use the following contingency table to determine whether variable 1 is independent of variable 2. Let α = .01 | Variable 2 | Variable1 | 24 | 13 | 47 | 58 | | 93 | 59 | 187 | 244 | Step 1 Ho: the two classifications are independent Ha: the two classifications are dependent Step 2 d.f = (r – 1) (c – 1) Step 3 α = 0.01 x 2 0.01, 3df = 11.3449 Step 4 Reject Ho if x 2 > 11.3449 | Variable 2 | Total | Variable1 | 24 (22.92) | 13 (14.10) | 47 (45.83) | 58 (59.15) | 142 | | 93 (94.08) | 59 (57.90) | 187 (188.17) | 244 (242.85) | 583

## Mat 540 Week 1 Assignment

1004 Words | 5 PagesAssignment #2 1) Improve the result from problem 4 of the previous assignment by showing that for every e> 0, no matter how small, given n real numbers x1,...,xn where each xi is a real number in the interval [0, 1], there exists an algorithm that runs in linear time and that will output a permutation of the numbers, say y1, ...., yn, such that ∑ ni=2 |yi - yi-1| < 1 + e. (Hint: use buckets of size smaller than 1/n; you might also need the solution to problem 3 from the first assignment!) 2) To evaluate FFT(a0,a1,a2,a3,a4,a5,a6,a7) we apply recursively FFT and obtain FFT( a0,a2,a4,a6) and FFT(a1,a3,a5,a7). Proceeding further with recursion, we obtain FFT(a0,a4) and FFT(a2,a6) as well as FFT(a1,a5) and FFT(a3,a7). Thus, from bottom up, FFT(a0,a1,a2,a3,a4,a5,a6,a7)

## Summary: M6 WPS Activity

479 Words | 2 PagesGive a complete explanation for the "Power ...__The power rule for exponents states that when raising an exponential expression to a power, keep the base and multiply the exponents. This also includes powers of products and powers of quotients.7. Give a complete explanation for the "Expanded... ___The expanded power rule for exponent’s states that every factor within parentheses is raised to the power outside the parentheses when the expression is simplified. Its helps to simplify an expression before using the expanded power rule.Page 2 of 28. Give a complete explanation for the "Negative ..._______The negative exponent rule states that when a variable or number is raised to a negative exponent, the expression may be rewritten as one divided the variable or number raised to that positive exponent.

### Algorithm Workbench Essay

330 Words | 2 Pages### Inro to Pc Programming Unit 5 Assignment 1 Homework

1059 Words | 5 Pages### Math 471 Week 1 Case Study

1035 Words | 5 Pages### Pt1420 Unit 2 Research Assignment 1 Researching Variable Naming Rules

386 Words | 2 Pages### Math Test Bus2023

2716 Words | 11 Pages### It/210 Week 6 Assignment

399 Words | 2 Pages### Nt1210 Lab 1.1

695 Words | 3 Pages### Nt1310 Unit 8 Regression Analysis

1629 Words | 7 Pages### Mat 540 Week 1 Assignment

1004 Words | 5 Pages### Summary: M6 WPS Activity

479 Words | 2 Pages