def getNumsFromBytes(bytes, bitsPerComponent=8):
 if (not isinstance(bytes, str)):
  return ((-1), 'bytes must be a string')
 if (not isinstance(bitsPerComponent, int)):
  return ((-1), 'bitsPerComponent must be an integer')
 outputComponents = []
 bitsStream = ''
 for byte in bytes:
  try:
   bitsRepresentation = bin(ord(byte))
   bitsRepresentation = bitsRepresentation.replace('0b', '')
   bitsRepresentation = (('0' * (8 - len(bitsRepresentation))) + bitsRepresentation)
   bitsStream += bitsRepresentation
  except:
   return ((-1), 'Error in conversion from bytes to bits')
 try:
  for i in range(0, len(bitsStream), bitsPerComponent):
   bytes = ''
   bits = bitsStream[i:(i + bitsPerComponent)]
   num = int(bits, 2)
   outputComponents.append(num)
 except:
  return ((-1), 'Error in conversion from bits to bytes')
 return (0, outputComponents)

def getNumsFromBytes ( bytes , bitsPerComponent = 8 ) : if ( not isinstance ( bytes , str ) ) : return ( ( - 1 ) , 'bytes must be a string' ) if ( not isinstance ( bitsPerComponent , int ) ) : return ( ( - 1 ) , 'bitsPerComponent must be an integer' ) outputComponents = [ ] bitsStream = '' for byte in bytes : try : bitsRepresentation = bin ( ord ( byte ) ) bitsRepresentation = bitsRepresentation . replace ( '0b' , '' ) bitsRepresentation = ( ( '0' * ( 8 - len ( bitsRepresentation ) ) ) + bitsRepresentation ) bitsStream += bitsRepresentation except : return ( ( - 1 ) , 'Error in conversion from bytes to bits' ) try : for i in range ( 0 , len ( bitsStream ) , bitsPerComponent ) : bytes = '' bits = bitsStream [ i : ( i + bitsPerComponent ) ] num = int ( bits , 2 ) outputComponents . append ( num ) except : return ( ( - 1 ) , 'Error in conversion from bits to bytes' ) return ( 0 , outputComponents )
makes the conversion between bytes and numbers .