Golang中十六进制的大数字

I'm trying to convert bignumbers(big.Int or even better big.Rat ) to Hex values.

I'm always having issue converting number when they are negative 0xff..xx or Fixed numbers.

Is there a way to do that ?

Not sure what kind of issues are you having, but big.Int, big.Float and big.Rat implement the fmt.Formatter interface, you can use the printf family with the %x %X to convert to hexadecimal string representation, example:

package main

import (
    "fmt"
    "math/big"
)

func toHexInt(n *big.Int) string {
    return fmt.Sprintf("%x", n) // or %X or upper case
}

func toHexRat(n *big.Rat) string {
    return fmt.Sprintf("%x", n) // or %X or upper case
}

func main() {
    a := big.NewInt(-59)
    b := big.NewInt(59)

    fmt.Printf("negative int lower case: %x
", a)
    fmt.Printf("negative int upper case: %X
", a) // %X or upper case

    fmt.Println("using Int function:", toHexInt(b))

    f := big.NewRat(3, 4) // fraction: 3/4

    fmt.Printf("rational lower case: %x
", f)
    fmt.Printf("rational lower case: %X
", f)

    fmt.Println("using Rat function:", toHexRat(f))
}

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