decimal to hexadecimal with fixed point
7 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Jessica Clayton
on 2 Dec 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.
0 Comments
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!