📄 ibm2num.m
字号:
function x=ibm2num(b)% ibm2num : convert IBM 32 bit floating point format to doubles% x=num2ibm(b)% b is a matrix of uint32% x is a corresponding matrix of doubles%%% See also num2ibm% % This program is free software; you can redistribute it and/or modify% it under the terms of the GNU General Public License as published by% the Free Software Foundation; either version 2 of the License, or% (at your option) any later version.%% This program is distributed in the hope that it will be useful,% but WITHOUT ANY WARRANTY; without even the implied warranty of% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the% GNU General Public License for more details.%% You should have received a copy of the GNU General Public License% along with this program; if not, write to the Free Software% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA%%% (C) Brian Farrelly, 22 October 2001% mailto:Brian.Farrelly@nho.hydro.com Norsk Hydro Research Centre% phone +47 55 99 68 74 ((( Postboks 7190% fax +47 55 99 69 70 2oooS N-5020 Bergen% home +47 55 13 78 49 HYDRO Norway%x=repmat(NaN,size(b));sign=bitget(b,32); % get sign from first bitsign=double(sign);% format hexexp=bitand(b,uint32(hex2dec('7f000000'))); % get exponent from first byte, last 7 bitsexp=bitshift(exp,-24);%format longexp=double(exp)- 64; % remove bias from exponent %format hexfrac=bitand(b,uint32(hex2dec('00ffffff'))); % get mantissa from last 3 bytes%format longfrac=double(frac);frac=frac/2^24;x=(1-2*sign).*16.^exp .* frac;err = frac==0 & (exp~=-64 | sign~=0); % bias removal is incorrect for zeroif any(err) % TMH 19/06/2003 disp(['WARNING : ',mfilename,' Invalid zero input --> Sure data are IBM FLOAT formatted ?']) return; %warning('Invalid zero input in ibm2num for the following:') % format hex; disp(b(err)); format enderr = frac~=0 & (frac<1/16 | frac>=1);if any(err) % TMH 19/06/2003 disp(['WARNING : ',mfilename,' Invalid mantissa input --> Sure data are IBM FLOAT formatted ?']) return; % warning('Invalid mantissa input in ibm2num for the following:') % format hex; disp(b(err)); format end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -