function disp_num(a,fmt) % disp_num(a,fmt): display binary representation of numbers % a = number or array to be displayed % fmt = format, 'int', 'single', or 'double' % binary digits are displayed in groups of 16 % NOTE: the bytes are in a different order than actually stored in memory % but they conform to what is in the book % write a into file file='disp.tmp'; fid=fopen(file,'w'); fwrite(fid,a,fmt); % now read for display fclose(fid); fid=fopen(file,'r'); t=fread(fid,inf,'uint16'); fclose(fid); switch fmt case {'int','single'} w=2; case {'double'} w=4; otherwise error('unknown format') end % permute as 2 1 4 3 6 5 etc r=reshape(1:length(t),w,length(t)/w); r=flipdim(r,1); [m,n]=size(r); for j=1:n, for i=1:m, rr=r(i,j); fprintf('%s ',dec2bin(t(rr),16)); end fprintf('\n'); end return