{"id":10740,"date":"2021-10-01T10:30:51","date_gmt":"2021-10-01T05:00:51","guid":{"rendered":"https:\/\/python-programs.com\/?p=10740"},"modified":"2021-11-22T18:33:27","modified_gmt":"2021-11-22T13:03:27","slug":"python-program-to-find-the-total-number-of-bits-needed-to-be-flipped","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-find-the-total-number-of-bits-needed-to-be-flipped\/","title":{"rendered":"Python Program to Find the Total Number of Bits Needed to be Flipped"},"content":{"rendered":"

Given two numbers the task is to print the number of bits to be flipped to convert the given number to the other number.<\/p>\n

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

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

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

given the first number = 12\r\ngiven the second number = 9<\/pre>\n

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

Binary representations of the given two numbers are :\r\n12 = 1100\r\n9 = 1001\r\nThe total number of bits to be flipped = 2<\/pre>\n

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

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

given the first number = 59\r\ngiven the second number = 3<\/pre>\n

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

Binary representations of the given two numbers are :\r\n59 = 111011\r\n3 = 11\r\nThe total number of bits to be flipped = 3<\/pre>\n

Program to Find the Total Number of Bits Needed to be Flipped<\/h2>\n

Below is the full approach to print the number of bits to be flipped to convert the given number to the other number.<\/p>\n