def float_to_byte(value, mantissabits=5, zeroexp=2):
 fzero = ((63 - zeroexp) << mantissabits)
 bits = unpack('i', pack('f', value))[0]
 smallfloat = (bits >> (24 - mantissabits))
 if (smallfloat < fzero):
  if (bits <= 0):
   result = chr(0)
  else:
   result = chr(1)
 elif (smallfloat >= (fzero + 256)):
  result = chr(255)
 else:
  result = chr((smallfloat - fzero))
 return b(result)

def float_to_byte ( value , mantissabits = 5 , zeroexp = 2 ) : fzero = ( ( 63 - zeroexp ) << mantissabits ) bits = unpack ( 'i' , pack ( 'f' , value ) ) [ 0 ] smallfloat = ( bits >> ( 24 - mantissabits ) ) if ( smallfloat < fzero ) : if ( bits <= 0 ) : result = chr ( 0 ) else : result = chr ( 1 ) elif ( smallfloat >= ( fzero + 256 ) ) : result = chr ( 255 ) else : result = chr ( ( smallfloat - fzero ) ) return b ( result )
encodes a floating point number in a single byte .