Skip to content

Commit

Permalink
Some comments for better understanding of question
Browse files Browse the repository at this point in the history
  • Loading branch information
NamanAg0502 authored May 12, 2022
1 parent 640ee0c commit 7fad6ee
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions DSA Preparation 450/Bit Manipulation/Bit Difference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,25 @@ int countBitsFlip(int a, int b){
int c=a^b;
while(c)
{
c = c&(c-1);


c = c&(c-1);
count++;
}
// 11110 = c
// 11101 = c-1
// c = c&(c-1);
// step -> 1
// c = 11100
// c-1 = 11011
// step -> 2
// c = 11000
// c-1 = 10111
// step -> 3
// c = 10000
// c-1 = 01111
// step -> 4
// c = 00000
// that means -> a^b == 0 -> a and b are equal.


return count;

Expand Down

0 comments on commit 7fad6ee

Please sign in to comment.