The Six Bitwise Operators
MediumRead three integers a, b, and n, then compute and print c = a & b, d = a | b, e = ~a, f = a >> n, g = a << n, and h = a ^ b, one per line in exactly this form: c = a & b = 8, d = a | b = 14, e = ~a = -13, f = a >> n = 3, g = a << n = 48, h = a ^ b = 6. Guard the shifts before computing anything: if a or b is negative print a and b must be non-negative; otherwise if n is below 0 or above 15 print n must be between 0 and 15; otherwise if a is greater than INT_MAX >> n, so that a << n would overflow, print a << n would overflow. Each of those returns 1 without printing any results. If the three integers cannot be read, print invalid input and return 1.
Success Criteria
Your code must pass 8 test case(s) to complete this exercise. 3 hint(s) are available if you need help.
How did you find this exercise?
Your rating helps us improve the content.
Sign in to track your progress
You can work on exercises as a guest, but sign in to track your progress and save your submissions.