Golang : Find the length of big.Int variable example
There is a chance that you will ever need to get the length of big.Int
variable and below is a simple example on how to count the length of a big.Int
variable.
package main
import (
"fmt"
"math/big"
)
func main() {
// base 10
bigInteger := new(big.Int)
bigInteger.SetString("100000000000000000L", 10) //18
fmt.Println("Value : ", bigInteger)
fmt.Println("Length : ", len(bigInteger.Text(10)))
}
Output:
Value : 100000000000000000
Length : 18
Reference:
https://www.socketloop.com/tutorials/golang-convert-string-or-integer-to-big-int-type
See also : Golang : Calculate Relative Strength Index(RSI) example
By Adam Ng(黃武俊)
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+7.4k Golang : Process json data with Jason package
+10.1k Golang : Bcrypting password
+9.1k Golang : does not implement flag.Value (missing Set method)
+25.6k Golang : How to write CSV data to file
+17.4k Golang : Linked list example
+5.7k Golang : ROT32768 (rotate by 0x80) UTF-8 strings example
+19.2k Golang : Execute shell command
+37.6k Golang : Comparing date or timestamp
+6.5k Elasticsearch : Shutdown a local node
+10k Golang : Edge detection with Sobel method
+17.7k How to enable MariaDB/MySQL logs ?