DEV Community

Discussion on: Bit difference

Collapse
 
lionelrowe profile image
lionel-rowe • Edited

JS one-liner version:

const countBitsFlip = (a, b) => [...(a ^ b).toString(2)].filter(x => x === '1').length
Enter fullscreen mode Exit fullscreen mode

Using toString is a bit of a filthy hack though 😂 plus perf is much worse