Skip to content

Commit

Permalink
feat(binary): add bitSize()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Nov 12, 2019
1 parent 9a2637c commit f085bfb
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/binary/src/count.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ export const ctz32 = (x: number) => {
x & 0x55555555 && (c -= 1);
return c;
};

/**
* Returns the number of bits required to encode `x` (MUST be > 0).
*
* @param x
*/
export const bitSize = (x: number) => Math.ceil(Math.log(x) / Math.LN2);

0 comments on commit f085bfb

Please sign in to comment.