GNU Octave fail hex2dec

Viewed 141

Encounter fail with some HEX to DEC conversions

b = '0x170d21b9' 
bdec = hex2dec(b)

Return the

bdec = NaN

But should be 386736569

How to convert the hexadecimal number to integer in above example?

1 Answers

Leave off the 0x. This is a notation used in some languages to denote that the number is hex, but isn't actually part of the number. Octave's hex2dec function doesn't use that. Put b = '170d21b9' and you will get bdec = 386736569.

Related