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=hex_2_oct(input)
function output=hex_2_oct(input)

% This function converts an hexadecimal number into corresponding octagonal number.
%  Class of both variables - output and input are "char".
%
% Example:
% hex_2_oct('7125378512AE32546DEF213ae43535fe2312d23145465787654d2e3c')
% ans =
% 161112336050452706225066757102353441523277610611322142425062570354523227074
input=char(input-32.*floor((sign(123-input)+sign(input-96))/2));
check1=sign(length(input-48)-sum(sign(abs(input-48+1)+(input-48+1))))+sign(sum(abs(input-48-22)+(input-48-22)));
check2=sign(sum(sign(abs(input-48-9)+(input-48-9))-sign(abs(input-48-16)+(input-48-16))));
if ( check1 || check2 )
    output ='Invalid Number';
else
    output=bin_2_oct(hex_2_bin(input));
end

Contact us