Skip to content

updated code #2922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

ehtashammd07
Copy link

Bit manipulation : Count number of bits to be flipped to convert A to B

Fixes #2921

Approach
Use XOR (^) to Identify Differing Bits

The XOR operation returns 1 when bits are different and 0 when they are the same.
xor_value = start ^ goal gives a number where 1s represent the bits that need to be flipped.
Count the Number of 1s in xor_value

We count the number of 1s in the binary representation of xor_value.
This is done using xor_value & 1 (to check the last bit) and xor_value >>= 1 (to shift right and check the next bit).

Copy link
Contributor

This pull request has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Author has not responded to the comments for over 2 weeks label Apr 11, 2025
Copy link
Contributor

Please ping one of the maintainers once you commit the changes requested or make improvements on the code. If this is not the case and you need some help, feel free to ask for help in our Gitter channel or our Discord server. Thank you for your contributions!

@github-actions github-actions bot closed this Apr 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Author has not responded to the comments for over 2 weeks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[OTHER] Bit manipulation : Count number of bits to be flipped to convert A to B
1 participant