string to big Int in Go?

前端 未结 2 968
难免孤独
难免孤独 2021-02-08 16:28

Is there a way to convert a string (which is essentially a huge number) from string to Big int in Go?

I tried to first convert it into bytes array

array :

2条回答
  •  粉色の甜心
    2021-02-08 17:12

    See Example for string to big int conversion.

    package main
    
    
    import (
        "fmt"
        "log"
        "math/big"
    )
    
    func main() {
        i := new(big.Int)
        _, err := fmt.Sscan("18446744073709551617", i)
        if err != nil {
            log.Println("error scanning value:", err)
        } else {
            fmt.Println(i)
        }
    }
    

    Output:

    18446744073709551617
    

提交回复
热议问题