Reputation: 1015
I want to interpret (not convert) ascii chars as their hex values. I.e., I have string = 'a';
It should be converted to hex value 0xa.
I only found solutions which convert the ascii value into its hex representation (which would be 0x61 but which is not the value I am looking for).
Upvotes: 0
Views: 818
Reputation: 17451
Use hex2dec
:
string = 'a'
numericvalue = hex2dec(string)
Documentation here: https://www.mathworks.com/help/matlab/ref/hex2dec.html?requestedDomain=www.mathworks.com
Internally, the value 0xa
is not stored as hex, or decimal, but as binary. But the number value is always the same, whether you write is as 10 (decimal), 0xa (hex), or 1010 (binary).
Upvotes: 2
Reputation: 1331
Matlab doesn't have a hex type but you probably want something like this.
sscanf('a','%x')
which would result an answer of 10. converting back to hex w/ dec2hex would recreate a string representation.
Upvotes: 0