%--------------------------------------------------------------------------
%   [dataout] = d2b(datain,N_bit)
%--------------------------------------------------------------------------
%   功能
%   转换10进制有符号数为二进制格式(常用于FPGA验证)
%--------------------------------------------------------------------------
%   输入:
%           datain                  10进制数
%           N_bit                   转换位数
%   output:
%           dataout                 二进制数
%--------------------------------------------------------------------------
%   例子:   
%   d2b(13,5)
%   ans =
%       "1101"
%   d2b(-13,5)
%   ans = 
%       "10011"
%--------------------------------------------------------------------------
function dataout = d2b(datain,N_bit)
[X,Y,Z] = size(datain);
datain(datain < 0) = datain(datain < 0)+2^N_bit;
h = dec2bin(datain);
for index = 1:X*Y*Z
    temp(index)= string(h(index,:));
end
dataout = reshape(temp,[X Y Z]);
end


    
    