如何使用go将十六进制转换为int [重复]

This question already has an answer here:

I converting hex value to decimal using go using below mentioned code

numberStr := strings.Replace(s, "0x", "", -1)
    numberStr = strings.Replace(numberStr, "0X", "", -1)
    n, err := strconv.ParseUint(numberStr, 16, 64)
    if err != nil {
        panic(err)
    }
    return n 

Hexa value is : 0x340aad21b3b700000

but thrown error : strconv.ParseUint: parsing "340aad21b3b700000": value out of range

Can you suggest any alternate solution.

</div>

Maximum value for uint64 is 0xFFFF FFFF FFFF FFFF, thus to use overflowing value you have to resort to package math/big of the standard library:

import "math/big"

...

n := new(big.Int)
n.SetString(numberStr, 16)

Continue with the package documentation.