{"id":20570,"date":"2021-09-15T19:49:17","date_gmt":"2021-09-15T14:19:17","guid":{"rendered":"https:\/\/python-programs.com\/?p=20570"},"modified":"2021-11-22T18:36:19","modified_gmt":"2021-11-22T13:06:19","slug":"python-program-print-bitwise-and-set-of-a-number-n","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-print-bitwise-and-set-of-a-number-n\/","title":{"rendered":"Python Program Print Bitwise AND set of a Number N"},"content":{"rendered":"

In the previous article, we have discussed Python Program to Toggle Bits of a Number Except First and Last bits<\/a><\/p>\n

Given a number and the task is to print all the bitwise AND set of a given number.<\/p>\n

For some number I the bitwise AND set of a number N is all feasible numbers x smaller than or equal to N such that N & I equals x.<\/p>\n

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

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

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

Given Number = 6<\/pre>\n

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

The all bitwise AND set of a given number{ 6 } : \r\n0  2  4  6<\/pre>\n

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

Iterating from 0 to 6 so\r\n0 & 6 = 0\r\n1 & 6 = 0                            \r\n2 & 6 = 2\r\n3 & 6 = 2\r\n4 & 6 = 4\r\n5 & 6 = 4\r\n6 & 6 = 6\r\nHence the all bitwise AND set of a given number = 0 2 4 6 (removing duplicates)<\/pre>\n

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

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

Given Number = 3<\/pre>\n

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

The all bitwise AND set of a given number{ 3 } : \r\n0  1  2  3<\/pre>\n

Program Print Bitwise AND set of a Number N in Python<\/h2>\n

Below are the ways to print all the bitwise AND set of a given number in Python:<\/p>\n