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

% This function converts a single-digit binary number into corresponding hexagonal number.
%  Class of both variables - output and input are "char".
mat_1=['0000';
    '0001';
    '0010';
    '0011';
    '0100';
    '0101';
    '0110';
    '0111';
    '1000';
    '1001';
    '1010';
    '1011';
    '1100';
    '1101';
    '1110';
    '1111';];

mat_2='0123456789ABCDEF';

for i=1:16
    if(input==mat_1(i,:))
        output=mat_2(i);
    end
end

Contact us