4.3 Bit manipulation (3)

Resources | Revision Questions | Computer Science

Login to see all questions

Click on a question to view the answer

1.

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.

2.

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.

3.

A microcontroller is used to control a set of LEDs. Each LED is controlled by a single bit in a register. You are given a program that needs to implement a function to turn on a specific LED. Explain, using appropriate bitwise operators, how you would modify a given register to achieve this. Provide a clear explanation of the steps involved and the reasoning behind your choices. Assume the register is an 8-bit register.