Search this website:
Pdf on Bitwise operators and their functios
- Categorized in: Interview Questions/Tutorials
Following are some excerpts from the document
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
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 (including 0 or all 1’s):
Use the following formula to isolate the rightmost 1-bit, producing 0 if none (e.g., 01011000
Use the following formula to isolate the rightmost 0-bit, producing 0 if none (e.g., 10100111
Use one of the following formulas to form a mask that identifies the trailing 0’s, producing all 1’s if (e.g., 01011000
The first formula has a little instruction-level parallelism.
Download the whole document in the attachment section