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
+9k Golang : Serving HTTP and Websocket from different ports in a program example
+16.1k Golang : convert string or integer to big.Int type
+5.3k Python : Delay with time.sleep() function example
+11k Golang : Web routing/multiplex example
+4.4k Java : Generate multiplication table example
+19.1k Golang : Populate dropdown with html/template example
+20.5k Golang : Read directory content with os.Open
+15.1k Golang : How to get Unix file descriptor for console and file
+8.4k Android Studio : Import third-party library or package into Gradle Scripts
+8.8k Golang : What is the default port number for connecting to MySQL/MariaDB database ?
+10.8k Nginx : TLS 1.2 support
+16.7k Golang : Get the IPv4 and IPv6 addresses for a specific network interface