{"id":20526,"date":"2021-09-15T19:50:38","date_gmt":"2021-09-15T14:20:38","guid":{"rendered":"https:\/\/python-programs.com\/?p=20526"},"modified":"2021-11-22T18:36:18","modified_gmt":"2021-11-22T13:06:18","slug":"python-program-to-check-if-a-number-has-bits-in-alternate-pattern","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-check-if-a-number-has-bits-in-alternate-pattern\/","title":{"rendered":"Python Program to Check if a Number has Bits in Alternate Pattern"},"content":{"rendered":"

In the previous article, we have discussed Python Program to Find XOR of Two Numbers Without Using XOR operator<\/a><\/p>\n

Given a number, the task is to check if the given Number has the bits in an alternate pattern<\/p>\n

For example, the number 42 has an alternate pattern, which is 101010 (after 1 we are getting 0 and next 1 so on).
\nIf it has an alternate bit pattern, print “Yes,” else “No.”<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given Number= 42<\/pre>\n

Output:<\/strong><\/p>\n

Yes, the given number{ 42 } has an alternate bit pattern<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given Number= 14<\/pre>\n

Output:<\/strong><\/p>\n

No, the given number{ 14 } doesn't have an alternate bit pattern<\/pre>\n

Program to Check if a Number has Bits in Alternate Pattern in Python<\/h2>\n

Below are the ways to check if a given number has bits in an alternate pattern in python:<\/p>\n