tsgzj
tsgzj

Reputation: 55

Hexadecimal String to Int conversion

I have a hexadecimal string like "0xff", and want to convert it to int, which is 255.

But Int.fromString "0xff" gives the answer 0.

I though that Int.scan would help. But I'm new to SML.

Upvotes: 1

Views: 481

Answers (1)

newacct
newacct

Reputation: 122489

You can do

StringCvt.scanString (Int.scan StringCvt.HEX) "0xff"

or

StringCvt.scanString (Int.scan StringCvt.HEX) "ff"

Upvotes: 3

Related Questions