function voltage=convertAFE(hex)
% This functions takes the 6 bytes reading from the
% AFE readings and converts to voltage reading.

%     hex=char(hex);
%     % convert the hex to binary
%     binary= hex2bin(hex);
%     for i=1:8
%         binary(i)=0;
%     end
%     
%     scaled_voltage=bi2de(binary);
    flag=0;
    scaled_voltage=hex2dec(hex);
    
   if scaled_voltage>= 2^22
       scaled_voltage=0;
       flag=1;
   end
    
    % scale the voltage in accordance with the datasheet
    voltage=scaled_voltage* 1.2 / (2^21);
end