Skip to content

prevPow2

Subhajit Sahu edited this page Aug 9, 2022 · 1 revision

Find largest power-of-2 less than or equal to given bigint.

Similar: prevPow2, prevPow10.
Similar: isPow2, prevPow2, nextPow2.


function prevPow2(x)
// x: a bigint

const xbigint = require('extra-bigint');


xbigint.prevPow2(32n);
// → 32n

xbigint.prevPow2(1023n);
// → 512n


References

Clone this wiki locally