Converting floating-point hexadecimal (string input) to decimal
Mostrar comentarios más antiguos
I am trying to convert a base-16 string input to a base-10 output. I have a current code, using the hex2dec function. However, it won't convert a hex input with a floating point. Is there any way I can do so? For example. input '2B.3A' should return output 43.2265625
I would also like to convert base 10 inputs to base 16, so if anyone has any links for such files, it would be a great help. Thank you for your time
%Input must be a string
function y = hex2double(n)
n = strtrim(n);
c=0;
i=1;
if isempty(find(n=='.', 1))
y = hex2dec(n);
else
j = find(n=='.');
intp=n(1:j-1);
floatp=n(j+1:end);
%if find 0 in the beginning of the fraction part
%-divide by [place-value needed] times (1+ number of 0's), add floating part to integer part
%after that:
%floatp=floatp/(10*(1+c));
%this is where things get out of hand
y = hex2double(intp)+hex2dec(floatp);
end
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!