EPI 4.1 Primitive Types Variant question 3: Test if X is a power of 2

We are looking at question 4.1 from Elements Of Programming Interviews in Python book.

Write expressions that uses bitwise operators, equality checks and boolean operators to test if x is a power of 2 in O(1) time.

Test if is a power of 2. i.e. evaluates to true for x = 1,2,4,8,16... false for all other values.

If you are applying for software engineering positions I highly recommend getting this book.

Here is the video I created which walk you through the solution.