Code covered by the BSD License  

Highlights from
NUMBER SYSTEMS/ BASE CONVERTER

image thumbnail

NUMBER SYSTEMS/ BASE CONVERTER

by

 

13 Aug 2006 (Updated )

Convert a number between different number systems-hex,oct,bin,dec.

output=oct_2_bin(input)
function output=oct_2_bin(input)

% This function converts an octagonal number into corresponding binary number.
%  Class of both variables - output and input are "char".
%
% Example:
% oct_2_bin('3532432436345324764546435345')
% ans =
% 11101011010100011010100011110011100101011010100111110100101100110100011101011100101
if ( sign(length(input-48)-sum(sign(abs(input-48+1)+(input-48+1))))+sign(sum(abs(input-48-7)+(input-48-7))) )
    output ='Invalid Number';
else
    if input=='0'
        output='0';
    else
        c=[];
        for i=1:length(input)
            c=[c oct2bin(input(i))]; %#ok<AGROW>
        end
        output=c(find(c-48,1):length(c));
    end
end

Contact us