Resources | Revision Questions | Computer Science
Click on a question to view the answer
Explain the purpose of the left shift operator (>) in binary arithmetic. Include a discussion of how these operators affect the value of a binary number and the potential for sign extension when performing right shifts on signed integers. Provide examples of when each operator would be appropriately used in a programming context.
Explain how bit manipulation can be used to perform multiplication and division by powers of 2. Provide a code example (in a language of your choice) demonstrating how to multiply a number by 8, and how to divide a number by 4 using bitwise shift operators. Discuss the efficiency of these methods compared to using the standard multiplication and division operators.
A system uses 8-bit integers. A variable `value` has the binary representation 11010101. Calculate the decimal equivalent of `value` and then perform a left shift by 4 bits and a right shift by 2 bits. Show the binary representation of `value` before and after each operation, and state the resulting decimal values. Include a discussion of any potential issues that might arise with the right shift operation if the number were negative.