dthy81285 2016-10-18 20:49
浏览 36
已采纳

显示巨大的十六进制字符串的基数10表示?

Trying to find how to have this hexa string "58068906d6194c6cbda7a6df" into it's base 10 representation.

I tried with this:

i, err := strconv.Parse("58068906d6194c6cbda7a6df", 16, 64)

Obviously I'm getting this error: parsing "58068906d6194c6cbda7a6df"; value out of range

I also need to take the base 10 string representation and get this hexa value back after some processing. i.e.:

base10 := "58068906d6194c6cbda7a6df" => to base 10 string some processing hexa := base10 => to base 16 string

Can I use the fmt package to dislpay the base 10? I know that displaying the hexa of a base 10 I could use %x, but what can I do with an existing string?

Thanks for your help, for a reason I cannot understand, I'm unable to find any way to do this.

  • 写回答

1条回答 默认 最新

  • douzhao6584 2016-10-18 20:57
    关注

    Your hex value is larger than int64 can hold, so you have to use a big.Int

    https://play.golang.org/p/OPPL43u6nB

    i := new(big.Int)
    i.SetString("58068906d6194c6cbda7a6df", 16)
    fmt.Println(i)
    

    To get a hex string representation from a big.Int, you can use the Text method:

    hex := i.Text(16)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 win2012 iscsi ipsec
  • ¥15 封装的 matplotlib animation 不显示图像
  • ¥15 python摄像头画面无法显示
  • ¥15 关于#3d#的问题:d标定算法(语言-python)
  • ¥15 cve,cnnvd漏洞扫描工具推荐
  • ¥15 图像超分real-esrgan网络自己训练模型遇到问题
  • ¥15 如何构建全国统一的物流管理平台?
  • ¥100 ijkplayer使用AndroidStudio/CMake编译,如何支持 rtsp 直播流?
  • ¥15 用js遍历数据并对非空元素添加css样式
  • ¥15 使用autodl云训练,希望有直接运行的代码(关键词-数据集)