bi2de.m

来自「数字通信第四版原书的例程」· M 代码 · 共 33 行

M
33
字号
function d = bi2de(b, p)
%BI2DE Converts binary to decimal format.
%       D = BI2DE(B) converts a binary representation vector B to a decimal
%       presentation D. When B is a matrix, the output D is a column vector
%       with each element being the transfer of a row of B.
%       The first element in B represents the lowest binary bit. For example
%       bi2de([1 0]) results in 1; bi2de([0 1]) results in 2.
%
%       D = BI2DE(B, P) converts a P-based vector to a decimal.
%
%       See also DE2BI.

%       Wes Wang 9/30/95
%       Copyright (c) 1995-96 by The MathWorks, Inc.
%       $Revision: 1.1 $  $Date: 1996/04/01 17:52:18 $

% check the special cases.
[n,m] = size(b);
if min([m,n]) < 1
    d = [];
    return;
elseif min([n,m]) == 1
    b = b(:)';
    m = max([n,m]);
    n = 1;
end;

if nargin < 2
    p = 2;
end;
d = b * p.^[0 : m-1]';
%---end of BI2DE---

⌨️ 快捷键说明

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