最近在玩以太坊,遇到将16进制转 big.Int 的需求

package main

import (
	"fmt"
	"math/big"
)

func main() {
	n := new(big.Int)
	m := new(big.Int)
	k := big.NewInt(1000000000000000000)
	n, ok := n.SetString("9184e72a9184e72a91e72a9184e72a9184e72a", 16)
	if !ok {
		fmt.Println("SetString: error")
		return
	}
	
	fmt.Println("big:", n )
	fmt.Println("div:",m.Div(n,k))
	fmt.Println("mod:",m.Mod(n,k))
}

输出

big: 3245185537339845905267089335704595216619333418
div: 3245185537339845905267089335
mod: 704595216619333418