decimal to hexadecimal with fixed point

7 visualizaciones (últimos 30 días)
Joao Costa
Joao Costa el 10 de En. de 2015
Respondida: Jessica Clayton el 2 de Dic. de 2020
I have the following code: that turns a string hexadecimal value into a numbers like [-0.12 -0.34 0.67 0.54 -0.128 0.256 ...]:
f_aux0 = fi(1,0,8,0);
% Read first value
t_dat0 = fgetl(fid0);
t_dat1 = fgetl(fid1);
% Get data arrays
while (i < l)
f_aux0.hex = t_dat0;
ADC(i) = (f_aux0.data - 2^7)/2^7;
(...)
that turns a string hexadecimal value into a numbers like [-0.12 -0.34 0.67 0.54 -0.128 0.256 ...].
I want to do the inverse, this means, to convert a number like [-0.12 -0.34 0.67(...) in hexadecimal with the same " fi "
I also tried something like this:
adc=adc + (adc<0).*2^7;
hexstring=dec2hex(adc, ceil(7/4));
But gave me an error, in some cases the values were negative...
If some one can help me.

Respuestas (1)

Jessica Clayton
Jessica Clayton el 2 de Dic. de 2020
I understand that you are trying to convert between decimal and hex notation for fixed point values. This answer provides several different methods of accomplishing this task.

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by