UNPKG

@dxzmpk/js-algorithms-data-structures

Version:

Algorithms and data-structures implemented on JavaScript

16 lines (13 loc) 295 B
/** * Return the number of bits used in the binary representation of the number. * * @param {number} number * @return {number} */ export default function bitLength(number) { let bitsCounter = 0; while ((1 << bitsCounter) <= number) { bitsCounter += 1; } return bitsCounter; }