def frac_to_b(num=0.0, width=8, endian='big'):
    """
    Convert a positive float which is less than 1.0 to a binary string.
    The returned value is 0xFF*num represented as a binary string
      when the width is 8 (default).
    This is useful for simulating fixed point arithmetic.
    
    The endianess is little by default but can be set to big to return a
      bit reversal.
    
    The returned string is can be converted to an int in Python by setting
      the base to 2 e.g.:'int( frac_to_b(...) , 2 )'.
    
    E.g. frac_to_b() returns 00000000
         frac_to_b(0.3, 5) returns 01010
         frac_to_b(0.5, width=10, endian='little') returns 0000000001
    """
    assert type(num
        ) is float, 'Invalid type : num : Expected %(expect)s : %(actual)s' % {
        'expect': str(type(float())), 'actual': str(type(num))}
    assert num < 1.0, 'Invalid value : num : Expected %(expect)s : %(actual)s' % {
        'expect': 'num < 1.0', 'actual': str(num)}
    assert type(width
        ) is int, 'Invalid type : width : Expected %(expect)s : %(actual)s' % {
        'expect': str(type(int())), 'actual': str(type(width))}
    assert width >= 0, 'Invalid value : width : Expected %(expect)s : %(actual)s' % {
        'expect': 'width >= 0', 'actual': str(width)}
    assert type(endian
        ) is str, 'Invalid type : endian : Expected %(expect)s : %(actual)s' % {
        'expect': str(type(str())), 'actual': str(type(endian))}
    assert endian == 'little' or endian == 'big', 'Invalid value: endian : Expected %(expect)s : %(actual)s' % {
        'expect': '"little" OR "big"', 'actual': str(endian)}
    a = int(round(num * 2 ** width))
    b = ''
    while a:
        b += str(a % 2)
        a = int(a / 2)
    t = b[::-1]
    del a, b
    if len(t) > width:
        t = t[:width]
    else:
        t = '0' * (width - len(t)) + t
    if endian == 'little':
        t = t[::-1]
    return t
