decimal to hexadecimal with fixed point

7 Ansichten (letzte 30 Tage)
Joao Costa
Joao Costa am 10 Jan. 2015
Beantwortet: Jessica Clayton am 2 Dez. 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.

Antworten (1)

Jessica Clayton
Jessica Clayton am 2 Dez. 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.

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by