⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dec2base_tab.m

📁 国外大学的同志作出来的好程序
💻 M
字号:
function mTable=dec2base_tab(Ndigits, Nbase, priority_type)
%dec2base_tab generates a table for the decimal figures to
%base N figures conversion. Nbase is the base for the desired
%figures. Ndigits is the number of digits in the
%converted base-N figures.
%If the priority_type is 'msb_first' or none,
%the first bit of the desired figures is the MOST significant
%bit (MSB) and the last bit is the least significant bit (LSB).
%Otherwise, the first bit is the LSB and the last bit is the MSB.
%The first bit is meant to the first left bits
if(nargin<2)
  disp('More arguments needed!');
  help(mfilename); return;
elseif(nargin<3 | isempty(priority_type))
  priority_type='msb_first';
end

if(Ndigits<=0) | (Nbase<=0)
   help(mfilename);
   mTable=[];
   return;
end;

MaxVal=Nbase^Ndigits-1;
mTable=zeros(MaxVal+1, Ndigits);

if strcmp(priority_type, 'msb_first'),
   vRadix=Nbase.^[Ndigits-1:-1:0];

   for jc=0:MaxVal,
      vDecTmp=zeros(1,Ndigits);
      ic=jc;
      for ic_degrp=1:Ndigits,
         vDecTmp(ic_degrp)=floor(ic/(vRadix(ic_degrp)));
         ic=ic-vDecTmp(ic_degrp)*vRadix(ic_degrp);
      end
      mTable(jc+1,:)=vDecTmp;

   end

elseif strcmp(priority_type, 'lsb_first')
      vRadix=Nbase.^[0:Ndigits-1];
   for jc=0:MaxVal,
      vDecTmp=zeros(1,Ndigits);
      ic=jc;
      for ic_degrp=Ndigits:-1:1,
         vDecTmp(ic_degrp)=floor(ic/(vRadix(ic_degrp)));
         ic=ic-vDecTmp(ic_degrp)*vRadix(ic_degrp);
      end
      mTable(jc+1,:)=vDecTmp;
   end
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -