Hex to Num / Hex Cell Array

7 views (last 30 days)
tinkyminky93
tinkyminky93 on 3 Jun 2022
Edited: Chunru on 3 Jun 2022
Hello I have a hex cell array and I indexed them.
For example I have 'A7' and when I use hex2dec, it gives me nonsense result which is -7.7452e-121. how can I get exact result? I mean I want to see that hex A7 = decimal 167.
Thank you.
  6 Comments
Chunru
Chunru on 3 Jun 2022
Edited: Chunru on 3 Jun 2022
hex2num inteprete 'A7' as IEEE double number (64bit) with mantissa and exponents. So padding 0's before 'A7'. The string is in a different order (from last byte to first byte) so it looks like (actually not) padding 0's after 'A7'.

Sign in to comment.

Accepted Answer

Chunru
Chunru on 3 Jun 2022
x ={'3A', 'F1', 'CF', '4C'}
x = 1×4 cell array
{'3A'} {'F1'} {'CF'} {'4C'}
y = cellfun(@hex2dec, x)
y = 1×4
58 241 207 76

More Answers (0)

Categories

Find more on Numeric Types in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by