Commit f39c1e97 authored by “Sivakorn”'s avatar “Sivakorn”

ส่งการบ้าน week04 ครับ

parent 9bb3a0cc
File added
def single_prec(v):
s=int(v[0]);
e='';
f=[];
x=1;
for i in range(1,len(v)):
if i>0 and i<9:
e+=v[i];
else:
f.append(v[i])
for i in range(0,len(f)):
y = int(f[i]);
xx = (-1)*(i+1)
x+=y*2**xx;
ee = int(e,2);
return((-1)**s * 2**(ee-127) *x)
def double_prec(v):
s=int(v[0]);
e='';
f=[];
x=1;
for i in range(1,len(v)):
if i>0 and i<12:
e+=v[i];
else:
f.append(v[i])
for i in range(0,len(f)):
y = int(f[i]);
xx = (-1)*(i+1)
x+=y*2**xx;
ee = int(e,2);
return((-1)**s * 2**(ee-1023) *x)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment