📄 int2bin.m
字号:
% MATLAB SIMULATION OF NSA FS-1016 CELP v3.2
% COPYRIGHT (C) 1995-99 ANDREAS SPANIAS AND TED PAINTER
%
% This Copyright applies only to this particular MATLAB implementation
% of the FS-1016 CELP coder. The MATLAB software is intended only for educational
% purposes. No other use is intended or authorized. This is not a public
% domain program and distribution to individuals or networks is strictly
% prohibited. Be aware that use of the standard in any form is goverened
% by rules of the US DoD. Therefore patents and royalties may apply to
% authors, companies, or committees associated with this standard, FS-1016. For
% questions regarding the MATLAB implementation please contact Andreas
% Spanias at (602) 965-1837. For questions on rules,
% royalties, or patents associated with the standard, please contact the DoD.
%
% ALL DERIVATIVE WORKS MUST INCLUDE THIS COPYRIGHT NOTICE.
%
% ******************************************************************
% INT2BIN
%
% DEVELOPED TO SUPPORT BITWISE OPERATIONS WHEN PORTING C TO MATLAB
% 3-30-94
%
% REVISED TO SUPPORT n-BIT INTEGERS INSTEAD OF 8-BIT
% 6-17-94
%
% REVISED TO HANDLE VECTORS OF INPUT VALUES IN a. ALL OUTPUT BINARY
% WORDS WILL BE OF LENGTH n BITS.
% 8-2-94
%
% ******************************************************************
%
% DESCRIPTION
%
% Obtain n-bit, 2's Compliment binary representation for an integer
% MATLAB variable. Input is an integer, output is a vector of n bits.
%
% DESIGN NOTES
%
% Use modulo division in place of bit mask, which would have been
% available in C. Encode negative values in 2's Compliment, as
% is done with most C compilers.
%
% SEE ALSO: BIN2INT
%
% VARIABLES
%
% INPUTS
% a - Input integer(s) (Actually double float in MATLAB)
% n - Number of bits desired
%
% OUTPUTS
% bv - n-bit, 2's Compliment bit vector(s), MSB first
%
% ******************************************************************
function bv = int2bin( a, n )
for i = 1:length(a)
% CONVERT USING MODULO DIVISION FOR BITMASK
% MASK HIGH BITS, THEN SUBTRACT REMAINING BITS
% CONVERT NEGATIVE VALUES TO 2'S COMP
if a(i) >= 0
bv(i,:) = sign(rem(a(i),2.^(n:-1:1))-rem(a(i),2.^((n-1):-1:0)));
else
a(i) = a(i) + 1;
bv(i,:) = ~sign(rem(a(i),2.^(n:-1:1))-rem(a(i),2.^((n-1):-1:0)));
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -