string to big Int in Go?

前端 未结 2 2007
再見小時候
再見小時候 2021-02-08 16:27

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:16

    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
    

提交回复
热议问题