# signed2bin function for MATLAB (alternatively Octave)

MATLAB, Octave @ 30 October 2010

Again Matlab does something that is not processable when you convert signed numbers to binary numbers. This function is for this purpose. Compatible with R2007 some small retouches needed for R2009

function [result] = signed2bin(a,len)
% signed2bin(a,len)
% a : an array of the signed decimal number
% len : the length of the bits you want to represent the signed numbers
 
b = dec2bin(a,len);
slas = find(b == '/');
if isempty(slas)
    result = b;
else
    b(slas) = '1';
    result = b;
end

Leave a Reply

*