contents.m
来自「Two functions, num2bin and bin2num are p」· M 代码 · 共 56 行
M
56 行
%contents% There are times when it is instructive to see a binary string% representation of a number. The function num2bin provides% functionality for creating this representation. Another function% bin2num reverses the operation. These scripts are useful in% an elementary numerical analysis course. Both functions% have been tested with MATLAB 5 or later.%% >x = pi;% >s = num2bin(x)% s =% % +.11001001000011111101101010100010001000010110100011000*2^+2% A 53 bit fraction is shown along with the scaling factor.%% The inverse operation is found in bin2num.% >z = bin2num(s)% z =% % 3.14159265358979% >z==x% ans =% 1%%Quantities of interest in numical analysis are eps, realmax, and realmin. The usual%formatting in MATLAB doesn't show the fine structure.% >z = num2bin(realmax)% z =% +.11111111111111111111111111111111111111111111111111111*2^+1024%%>z = num2bin(realmin)% z =% +.10000000000000000000000000000000000000000000000000000*2^-1021%% You can see denormalized numbers.% >z = num2bin(.25*realmin)% z =% +.10000000000000000000000000000000000000000000000000000*2^-1023%%It is easy to see how eps behaves.% >z = num2bin(eps)% z =% +.10000000000000000000000000000000000000000000000000000*2^-51% >z = num2bin(1+eps)% z =% +.10000000000000000000000000000000000000000000000000001*2^+1% >z = num2bin(1+eps*.5)% z =% +.10000000000000000000000000000000000000000000000000000*2^+1%% Herman Gollwitzer% Mathematics and Computer Science% Drexel University% hgollwit@mcs.drexel.edu
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?