← Bitwise Operators

Check a Bit

easy

Read n and a bit position (0 = least significant bit), and print Set or Clear depending on that specific bit’s value in n.

This is the “check” third of the set/check/clear idiom from the lesson: build a mask with a single 1 bit at position using 1 << position, & it with n, and compare the result against 0. Don’t forget the parentheses around n & (1 << position) before comparing with != – bitwise operators bind looser than comparisons, exactly as the lesson warns.

Your solution

"Run" uses the sample stdin ("5 0"). "Submit" checks your code against all 4 test cases.

Test results

Submit your solution to run it against all test cases.

Hints

    Reference solution