mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2026-02-04 10:33:51 +08:00
Add bitsDiff function.
This commit is contained in:
13
src/algorithms/math/bits/bitsDiff.js
Normal file
13
src/algorithms/math/bits/bitsDiff.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import countSetBits from './countSetBits';
|
||||
|
||||
/**
|
||||
* Counts the number of bits that need to be change in order
|
||||
* to convert numberA to numberB.
|
||||
*
|
||||
* @param {number} numberA
|
||||
* @param {number} numberB
|
||||
* @return {number}
|
||||
*/
|
||||
export default function bitsDiff(numberA, numberB) {
|
||||
return countSetBits(numberA ^ numberB);
|
||||
}
|
||||
Reference in New Issue
Block a user