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

📄 de2bi.m

📁 数字通信第四版原书的例程
💻 M
字号:
function b = de2bi(d, n, p)
%DE2BI  Converts a positive decimal numbers to binary numbers.
%       B = DE2BI(D) converts a positive integer decimal vector D to a binary
%       matrix B. Each row of the binary matrix B represents the corresponding
%       number in D.
%
%       B = DE2BI(D, N) specifies the column number for matrix B. N is a
%       positive scalar number.
%
%       B = BI2DE(D, N, P) converts a decimal vector D to base P matrix.
%
%       The first element in B represents the lowest binary bit. For example
%       bi2de(1, 2) results in [1 0]; bi2de(2) results in [0 1].
%
%       See also BI2DE.

%       Wes Wang    6/13/94, 10/3/95
%       Copyright (c) 1995-96 by The MathWorks, Inc.
%       $Revision: 1.1 $  $Date: 1996/04/01 17:56:23 $

% routine check
d = d(:);
len_d = length(d);
if min(d) < 0
    error('Cannot convert a negative number');
end;

% assign the length
if nargin < 2;
    tmp = max(d);
    b1 = [];
    while tmp > 0
        b1 = [b1 rem(tmp, 2)];
        tmp = floor(tmp/2);
    end;
    n = length(b1);
end;
if nargin < 3
    p = 2;
end;

% initial value
b = zeros(len_d, n);

% parameter assignment
for i = 1 : len_d
    j = 1; 
    tmp = d(i);
    while (j <= n) & (tmp > 0)
        b(i, j) = rem(tmp, p);
        tmp = floor(tmp/p);
        j = j + 1;
    end;
end;

%---end of DE2BI---

⌨️ 快捷键说明

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