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)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答