0
0
Cprogramming~10 mins

Left shift and right shift in C - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to left shift the number 1 by 3 positions.

C
int result = 1 [1] 3;
printf("%d\n", result);
Drag options to blanks, or click blank then click option'
A<<
B>>
C+
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using the right shift operator instead of left shift.
Using arithmetic operators like + or -.
2fill in blank
medium

Complete the code to right shift the number 16 by 2 positions.

C
int result = 16 [1] 2;
printf("%d\n", result);
Drag options to blanks, or click blank then click option'
A>>
B<<
C+
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using the left shift operator instead of right shift.
Using arithmetic operators like + or -.
3fill in blank
hard

Fix the error in the code to correctly left shift the variable x by 4.

C
int x = 2;
int y = x [1] 4;
printf("%d\n", y);
Drag options to blanks, or click blank then click option'
A>>
B<<
C+
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using right shift operator instead of left shift.
Using arithmetic operators.
4fill in blank
hard

Fill both blanks to create a dictionary-like structure using bit shifts: shift 1 left by 5 and shift 32 right by 3.

C
int a = 1 [1] 5;
int b = 32 [2] 3;
printf("%d %d\n", a, b);
Drag options to blanks, or click blank then click option'
A<<
B>>
C+
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong shift operators.
Using arithmetic operators instead of shifts.
5fill in blank
hard

Fill all three blanks to compute: shift x left by 2, y right by 1, and add z.

C
int x = 3, y = 8, z = 5;
int result = (x [1] 2) + (y [2] 1) + [3];
printf("%d\n", result);
Drag options to blanks, or click blank then click option'
A<<
B>>
Cz
Dy
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up shift operators.
Adding wrong variables.