I had a data in single precision I had converted it into uint8 using type cast but now I want to change it to hex then what to do?
2 views (last 30 days)
Show older comments
for this
y = 1.2857e-39;
y = single(y);
z = typecast(y,'uint8');
disp(z)
my result is 2 0 14 0.
Now I want to convert it into hex what to do or any other way to directly convert single precission into hex.
I have alreaty tried some number to string conversions but it won't work.
0 Comments
Answers (1)
Walter Roberson
on 1 Dec 2015
sprintf('%02x', z)
5 Comments
Walter Roberson
on 1 Dec 2015
I am not "Buddy" and I am not "dude".
a = sprintf('%02x', z)
gives me 02000e00 for a, which looks like hex to me.
a = num2hex(y)
gives me 000e0002 which again looks like hex to me. The difference compared to the typecast / sprintf() has to do with byte orders, with num2hex() putting the most significant byte first but typecast() using whatever internal order happens to be used by the processor.
If what you are looking for is not one of those two strings, then exactly what string are you looking for? Perhaps
a = sprintf('%02X ',z); disp(a)
02 00 0E 00
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!