Package envi :: Module bits
[hide private]
[frames] | no frames]

Module bits

source code

A file full of bit twidling helpers

Functions [hide private]
 
unsigned(value, size)
Make a value unsigned based on it's size.
source code
 
signed(value, size)
Make a value signed based on it's size.
source code
 
is_signed(value, size) source code
 
sign_extend(value, cursize, newsize)
Take a value and extend it's size filling in the space with the value of the high order bit.
source code
 
is_parity(val) source code
 
is_parity_byte(bval)
An "optimized" parity checker that looks up the index.
source code
 
lsb(value) source code
 
msb(value, size) source code
 
is_signed_overflow(value, size) source code
 
is_unsigned_carry(value, size) source code
 
is_aux_carry(src, dst) source code
 
parsebytes(bytes, offset, size, sign=False, bigend=False)
Mostly for pulling immediates out of strings...
source code
 
slowparsebytes(bytes, offset, size, sign=False, bigend=False) source code
 
buildbytes(value, size, bigend=False) source code
 
byteswap(value, size) source code
 
intwidth(val) source code
 
hex(value, size=None) source code
 
binrepr(intval, bitwidth=None)
Return a string of one's and zero's for the given value.
source code
 
binary(binstr)
Decode a binary string of 1/0's into a python number
source code
 
binbytes(binstr)
Decode a binary string of 1/0's into a python binary string.
source code
 
parsebits(bytes, offset, bitoff, bitsize)
Parse bitsize bits from the bit offset bitoff beginning at offset bytes.
source code
Variables [hide private]
  MAX_WORD = 8
  u_maxes = [0, 255, 65535, 16777215, 4294967295, 1099511627775,...
  sign_bits = [0, 128, 32768, 8388608, 2147483648, 549755813888,...
  s_maxes = [0, 127, 32767, 8388607, 2147483647, 549755813887, 1...
  b_masks = [0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, ...
  parity_table = [True, False, False, True, False, True, True, F...
  le_fmt_chars = (None, 'B', '<H', None, '<L', None, None, None,...
  be_fmt_chars = (None, 'B', '>H', None, '>L', None, None, None,...
  hex_fmt = {1: '0x%.2x', 2: '0x%.4x', 4: '0x%.8x', 8: '0x%.16x'}
  __package__ = 'envi'
  i = 255
Function Details [hide private]

parsebits(bytes, offset, bitoff, bitsize)

source code 

Parse bitsize bits from the bit offset bitoff beginning at offset bytes.

Example:


Variables Details [hide private]

u_maxes

Value:
[0,
 255,
 65535,
 16777215,
 4294967295,
 1099511627775,
 281474976710655,
 72057594037927935,
...

sign_bits

Value:
[0,
 128,
 32768,
 8388608,
 2147483648,
 549755813888,
 140737488355328,
 36028797018963968,
...

s_maxes

Value:
[0,
 127,
 32767,
 8388607,
 2147483647,
 549755813887,
 140737488355327,
 36028797018963967,
...

b_masks

Value:
[0,
 1,
 3,
 7,
 15,
 31,
 63,
 127,
...

parity_table

Value:
[True,
 False,
 False,
 True,
 False,
 True,
 True,
 False,
...

le_fmt_chars

Value:
(None, 'B', '<H', None, '<L', None, None, None, '<Q')

be_fmt_chars

Value:
(None, 'B', '>H', None, '>L', None, None, None, '>Q')