Complete the code to left shift the variable value by 2 bits.
int value = 5; int result = value [1] 2;
The left shift operator << moves bits to the left, effectively multiplying the number by 2 for each shift.
Complete the code to right shift the variable value by 3 bits.
unsigned int value = 32; unsigned int result = value [1] 3;
The right shift operator >> moves bits to the right, effectively dividing the number by 2 for each shift.
Fix the error in the code to correctly perform a left shift by 1 bit.
int value = 10; int result = value [1] 1;
The correct operator for left shift is <<. Using >> would shift bits to the right.
Fill both blanks to complete the loop that left shifts numbers greater than 3 by 2 bits into the shifted array.
int numbers[] = {1, 2, 3, 4, 5};
int shifted[5];
int idx = 0;
for(int i = 0; i < 5; i++) {
if(numbers[i] [1] 3) {
shifted[idx++] = numbers[i] [2] 2;
}
}The condition uses > to check numbers greater than 3. The left shift operator << shifts bits left by 2.
Fill all three blanks to create a loop that right shifts each number by 1 bit if it is less than 10, otherwise left shifts by 1 bit.
int numbers[] = {5, 10, 15};
int results[3];
for(int i = 0; i < 3; i++) {
if(numbers[i] [1] 10) {
results[i] = numbers[i] [2] 1;
} else {
results[i] = numbers[i] [3] 1;
}
}The condition uses < to check if the number is less than 10. If true, it right shifts (>>) by 1 bit; otherwise, it left shifts (<<) by 1 bit.