octave 06 and 08WIP
This commit is contained in:
parent
e9d7aa3900
commit
c3777e550b
15 changed files with 303 additions and 0 deletions
18
1sem/octave/06/read_num_bin.m
Normal file
18
1sem/octave/06/read_num_bin.m
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
function n = read_num_bin(s)
|
||||
neg = s(1) == "-";
|
||||
if neg
|
||||
s = substr(s, 2);
|
||||
end
|
||||
ind = find(s == '.');
|
||||
decpart = s(1:ind-1);
|
||||
floatpart = s(ind+1:end);
|
||||
n = bin2dec(decpart);
|
||||
for d = 1:length(floatpart)
|
||||
if floatpart(d) == '1'
|
||||
n = n + 2^(-d);
|
||||
end
|
||||
end
|
||||
if neg
|
||||
n = -n;
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue