Separate the digits in a hex number
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
fiona rozario
am 18 Feb. 2017
Kommentiert: fiona rozario
am 19 Feb. 2017
I want to use the digits from hex numbers as indices to a lookup table. Eg: if the number is A9, A corresponds to the row of the lookup table and 9 corresponds to the column, so that I can pick up the value of the cell at the intersection of this row and column.
How can I separate 'A' and '9' in hex?
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 18 Feb. 2017
>> sscanf('A9', '%1x')
ans =
10
9
Weitere Antworten (1)
John D'Errico
am 18 Feb. 2017
Bearbeitet: John D'Errico
am 18 Feb. 2017
If you want the digits as an index into a table, then since indexing is 1-based in MATLAB, you want 'A' to map to 11, '9' maps to 10, '0' to 1, etc.
This will do:
H = 'F5A9';
[~,ind] = ismember(H,'0123456789ABCDEF')
ind =
16 6 11 10
Siehe auch
Kategorien
Mehr zu Tables 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!