美文网首页
golang 16进制转换10进制

golang 16进制转换10进制

作者: 已不再更新_转移到qiita | 来源:发表于2018-04-28 13:21 被阅读499次
    package main
    
    import (
        "fmt"
        "strconv"
    )
    
    func main() {
        hex := "0xC40C5253"
        val := hex[2:]
        
        n, err := strconv.ParseUint(val, 16, 32)
        if err != nil {
            panic(err)
        }
        
        n2 := uint32(n)
        fmt.Print(n2)
    }
    

    float64 convert to string

    package main
    
    import "fmt"
    import "strconv"
    
    func FloatToString(input_num float64) string {
    
        // to convert a float number to a string
        return strconv.FormatFloat(input_num, 'f', 6, 64)
    }
    
    func main() {
        fmt.Println(FloatToString(21312421.213123))
    }
    

    string hex convert to big.Int

    
    hexToBigInt("0x12a05f200")
    
    func hexToBigInt(hex string) *big.Int {
        n := new(big.Int)
        n, _ = n.SetString(hex[2:], 16)
    
        return n
    }
    

    参考:
    https://play.golang.org/p/IL76yCuzsMh

    https://blog.linux-mac.com/2018/06/01/33.html

    相关文章

      网友评论

          本文标题:golang 16进制转换10进制

          本文链接:https://www.haomeiwen.com/subject/ctrglftx.html