I'm researching a solution in order to convert a string (in my case the string is "05f8") into a uint16.I made research but I don't find a solution.Does anyone know how to do this?
Thanks for your help!
I'm researching a solution in order to convert a string (in my case the string is "05f8") into a uint16.I made research but I don't find a solution.Does anyone know how to do this?
Thanks for your help!
收起
Use strconv.ParseUint
(doc).
var s = "05f8"
var base = 16
var size = 16
value, err := strconv.ParseUint(s, base, size)
Note that the output value is an uint64
, you have to cast it to you type before using it.
Note (bis) that the size parameter control the maximum size of the uint to convert to, so the overflow check is done correctly.
报告相同问题?