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

📄 num2bool.m

📁 this is for demo in matlab
💻 M
字号:
function B = num2bool( R, n )
% num2bool - Convert Integer to Boolean number
%
% B = num2bool ( R, n )
%
% R - integer number to convert
% n - number of bits to use
% B - boolean number
%
% num2bool ver. 1                                  Last update: 24 Feb 2007

% Copyright 2002-2007        Andrey Popov              andrey.popov@gmx.net

% This software is published under the GNU GPL, by the free software
% foundation. For further reading see: 
% http://www.gnu.org/licenses/licenses.html#GPL

B = zeros(1,n);
for j=1:n
    K = 2^(n-j);
    if  R >= K          % is it bigger than the corresponing power of 2?
        B(j) = 1;       % set the bit to 1
        R = R - K;      % update R
    end
end

⌨️ 快捷键说明

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