hey guys...
I just need a little help with my encoder...
this is the problem:
Click Here
my code:
def f(byte_size,value):
e=((byte_size*8)-1)//(byte_size+1)+(byte_size>2)*byte_size//2
m,b=[((byte_size*8)-(1+e)), ~(~0 << e-1)]
OS= '1' if value<0 else '0' #sign
I,F=str(abs(value)).split('.')
I=bin(int(I)).replace('0b','')
FB=''
l=0; r = int(''.join(['1']*e),2)+m
while l<r:
B,F=str(float('0.'+F)*2.).split('.')
FB+=B
if F=='0': break
l+=1
#print FB
E=0
M=''
if I=='0':
while True:
if FB[-E]=='0': E-=1
else: break
M=FB[-E:-E+m]
E+=2-b #not sure why I need 2 when I should only need 1
else:
E=(len(I)-1)-b
M=(I+FB)[1:1+m]
E = bin(E+int('1'*(e-1))).replace('0b','')
OE = ('0'*(e-len(E)))+E if len(E)<e else E[0:e]
OM = ('0'*(m-len(M)))+M if len(M)<m else M[0:m]
print OS+' '+OE+' '+OM
sorry for the sloppy coding... >_<
I should've commented a little more.
and I know string handling is quite slow...
I'll handle by binary later.
also, the encoder was built to encode floats of any specified byte-length