nybblechr_to_01_dqs={'-':'-','0':'0000', '1':'0001', '2':'0010', '3':'0011', '4':'0100', '5':'0101', '6':'0110', '7':'0111', '8':'1000', '9':'1001', 'A':'1010', 'B':'1011', 'C':'1100', 'D':'1101', 'E':'1110', 'F':'1111', 'a':'1010', 'b':'1011', 'c':'1100', 'd':'1101', 'e':'1110', 'f':'1111'}

# Into to binary
def i2b(j, wd=0):
  return ''.join(map(nybblechr_to_01_dqs.__getitem__, '%02X' % j))[-wd:].zfill(wd)      # SJH 07/29/2004 20:26:03
  
# Char to binary
def c2b(c, wd=0):
  return ''.join(map(nybblechr_to_01_dqs.__getitem__, '%02X' % ord(c)))[-wd:].zfill(wd) # SJH 07/29/2004 20:26:03
  
# String to binary
def s2b(s, wd=0):
  return ''.join(map(nybblechr_to_01_dqs.__getitem__, '%02X'*len(s) % tuple(map(ord, s))))[-wd:].zfill(wd) # SJH 07/29/2004 20:26:03
    
# Binary to char
def b2c(b):
  chr(int(b,2))
