You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
13 lines
272 B
JavaScript
13 lines
272 B
JavaScript
2 years ago
|
"use strict";
|
||
|
|
||
|
const assert = require("assert");
|
||
|
const log2 = require("@extra-bigint/log2");
|
||
|
|
||
|
module.exports = function countBits(number) {
|
||
|
assert(number >= 0n);
|
||
|
|
||
|
return (number === 0n)
|
||
|
? 1 // Special case, log2 would return null here
|
||
|
: Number(log2(number)) + 1;
|
||
|
};
|