Bitwise Operators
Completed
Read two non-negative integers a and b. Print a & b, a | b, a ^ b, a << 2 and a >> 1.
Input
Two integers.
Output
One line, five numbers.
Example
Input
12 10
Output
8 14 6 48 6
Editor
C
Hints
& keeps bits set in both, | in either, ^ in exactly one.
Solution explanation
Shifting left by k multiplies by 2ᵏ; shifting right divides by 2ᵏ.
Show solution
#include <stdio.h>
int main() {
int a, b;
scanf("%d %d", &a, &b);
printf("%d %d %d %d %d\n", a & b, a | b, a ^ b, a << 2, a >> 1);
return 0;
}