Home » Javascript » How to find Bit Difference between two numbers in Javascript

How to find Bit Difference between two numbers in Javascript

Posted by: admin August 19, 2018 Leave a comment

Questions:

Suppose I have 2 numbers e.g. 1 and 2.Their binary representation is ’01’ and ’10’ so their bit difference is 2.For numbers 5 and 7 binary representation will be ‘101’ and ‘111’ so the bit difference is 1.Surely I can convert both the numbers to binary and then loop it to find the difference but is there any simpler way.??

Answers: