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

% This function converts an hexagonal number into corresponding decimal number.
%  Class of both variables - output and input are "char".
%
% Example:
% hex_2_dec('7125378512AE32546DEF213ae43535fe2312d23145465787654d2e3c')
% ans =
% 11915599092607191739039367662030936125233731628115520027914010439228
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_dec(hex_2_bin(input));
end

Contact us