Brought to you by: gregsmith

Name | Modified | Size | Downloads / Week | Status |
---|---|---|---|---|

Totals: 2 Items | 1.6 kB | 1 | ||

pybitop | 2012-10-14 | 1 | ||

README | 2012-10-14 | 1.6 kB | 1 |

pybitop supplies bit-level operations on integers for Python.
This module contains functions to perform bit level operations,
e.g. bit extraction, reversal, counting; sign extension.
Generally, inputs may be Python 'int' or 'long' types
interchangably; return values are 'int' objects where possible and
long' when the result does not fit in an int.
functions:
bit(ival,n) = bit at posn n; n >= 0
bitwidth(ival) = #bits required to hold ival (ival >= 0)
this is ceil(log2(ival+1))
bitwidth_signed(ival) = # signed bits required to hold ival
lowest_one(ival) = index of lowest '1' bit (-1 if ival is 0)
bit_extract(ival,lo,hi) extract range of bits from ival
bit_insert(ival1,lo,hi,ival2)
field_mask( lo, hi) == sum(2**i for i in range(lo,hi))
sign_extend(ival,n) - discard bits n up; extend bit
n-1 upwards. n>=1.
bit_reverse(ival,n) - discard bits n up; bit-reverse the
bits below n
popcount(ival,n=None) - count all 1's in lower n
bits (all bits if n missing; ival must be >=0 in this
case).
int_from_bytes( string [, byteorder])
convert bytes to a single integer; 'byteorder' is
'<' for little-endian, '>' for big-endian, '' for
native (default).
int_to_bytes( k, nbytes [, byteorder])
convert a single integer to bytes; 'byteorder' is
'<' for little-endian, '>' for big-endian, '' for
native (default).
Requires at least python 2.2; this release works up to Python 2.7, but does not support 3.x