#integer #logarithm #bitops

bin+lib ilog2

Integer logarithm library including some bit operations

7 releases

Uses old Rust 2015

0.2.2 Jul 31, 2015
0.2.1 Jul 31, 2015
0.1.1 Jul 31, 2015
0.0.2 Jul 9, 2015

#6 in #logarithm


Used in bitalloc

MIT license

13KB
340 lines

#Integer Logarithm Library for Rust

##API List

  1. roundup_pow2(x), rounddown_pow2(x) for u8 ... u64, returns same integer type.
  2. bit_length<u8 ... u64>(), returns usize
  3. bit_mask<u8 ... u64>(), returns self-typed 0xFF...FF
  4. msb(x), lsb(x), msz(x), lsz(x) for u8 ... u64, returns i8, -1i8 on error. Index starts from 0.
  5. ffs(x), fls(x), ffz(x), flz(x) for u8 ... u64, returns u8, 0u8 means error. Index starts from 1.
  • msb: Find first 1 bit from msb position. Return its index (index starts from lsb).
  • lsb: Find first 1 bit from lsb position. Return its index (index starts from lsb).
  • msz, lsz: Find 0 like above.
  • ffs, fls, ffz, flz: +1 to lsb, msb, lsz, msz

Dependencies

~465KB