From 7fad6ee91a72c188a387d3f68a592a1060c24114 Mon Sep 17 00:00:00 2001 From: Naman Agrawal Date: Fri, 13 May 2022 04:35:12 +0530 Subject: [PATCH] Some comments for better understanding of question --- .../Bit Manipulation/Bit Difference.cpp | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/DSA Preparation 450/Bit Manipulation/Bit Difference.cpp b/DSA Preparation 450/Bit Manipulation/Bit Difference.cpp index 65fa3c4..7301c04 100644 --- a/DSA Preparation 450/Bit Manipulation/Bit Difference.cpp +++ b/DSA Preparation 450/Bit Manipulation/Bit Difference.cpp @@ -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;