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
 
is_aux_carry_sub(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 = 16
  u_maxes = [(2**(8* i))-1 for i in range(MAX_WORD+ 1)]
  sign_bits = [(2**(8* i)) >> 1 for i in range(MAX_WORD+ 1)]
  s_maxes = [u_maxes [i] ^ sign_bits [i] for i in range(len(u_ma...
  b_masks = [(2** i)-1 for i in range(MAX_WORD* 8)]
  parity_table = []
  le_fmt_chars = None, "B", "<H", None, "<L", None, None, None, ...
  be_fmt_chars = None, "B", ">H", None, ">L", None, None, None, ...
  hex_fmt = {0: '0x%.1x', 1: "0x%.2x", 2: "0x%.4x", 4: "0x%.8x",...
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]

s_maxes

Value:
[u_maxes [i] ^ sign_bits [i] for i in range(len(u_maxes))]

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"

hex_fmt

Value:
{0: '0x%.1x', 1: "0x%.2x", 2: "0x%.4x", 4: "0x%.8x", 8: "0x%.16x",}