Hexadecimal conversion of golang language

func main(){
    n := "0fa8" 
    // 4008
}

the question is this: there is a hexadecimal string type of "0fa8", converted to decimal to 4008, how to convert a hexadecimal string into plastic shaping?
tried fmt.Sprintf and strconv but failed.

Go
May.31,2022

num, _: = strconv.ParseInt ("0fa8", 16,0)


also has a method you found yourself, using strconv.ParseInt .


<ol> <li> 16 , hex.DecodeString() </li> <li>, binary.BigEndian.Uint16() </li> </ol>

package main

import (
    "encoding/binary"
    "encoding/hex"
    "fmt"
)

func main() {
    bs, _ := hex.DecodeString("0fa8")
    num := binary.BigEndian.Uint16(bs[:2])
    fmt.Println(num)
}
Menu