def getBitsFromNum(num, bitsPerComponent=8):
 if (not isinstance(num, int)):
  return ((-1), 'num must be an integer')
 if (not isinstance(bitsPerComponent, int)):
  return ((-1), 'bitsPerComponent must be an integer')
 try:
  bitsRepresentation = bin(num)
  bitsRepresentation = bitsRepresentation.replace('0b', '')
  mod = (len(bitsRepresentation) % 8)
  if (mod != 0):
   bitsRepresentation = (('0' * (8 - mod)) + bitsRepresentation)
  bitsRepresentation = bitsRepresentation[((-1) * bitsPerComponent):]
 except:
  return ((-1), 'Error in conversion from number to bits')
 return (0, bitsRepresentation)

def getBitsFromNum ( num , bitsPerComponent = 8 ) : if ( not isinstance ( num , int ) ) : return ( ( - 1 ) , 'num must be an integer' ) if ( not isinstance ( bitsPerComponent , int ) ) : return ( ( - 1 ) , 'bitsPerComponent must be an integer' ) try : bitsRepresentation = bin ( num ) bitsRepresentation = bitsRepresentation . replace ( '0b' , '' ) mod = ( len ( bitsRepresentation ) % 8 ) if ( mod != 0 ) : bitsRepresentation = ( ( '0' * ( 8 - mod ) ) + bitsRepresentation ) bitsRepresentation = bitsRepresentation [ ( ( - 1 ) * bitsPerComponent ) : ] except : return ( ( - 1 ) , 'Error in conversion from number to bits' ) return ( 0 , bitsRepresentation )
makes the conversion between number and bits .