Alternating Bits in Binary

BIT MANIPULATION

Problem

Given an integer n, check if its binary representation consists of alternating 0s and 1s. The function should return true if the binary sequence is alternating, and false otherwise.

Examples

hasAlternatingBits(10) // returns true // The binary representation of 10 is 1010 hasAlternatingBits(3) // returns false // The binary representation of 3 is 11
Loading...