Golang : convert string or integer to big.Int type
Problem :
You have a big integer number in string format and you want to convert(cast) it to big.Int type. How to do that?
Solution :
Use math/big.Int
type. Create a new big.Int type variable and the set the value with SetString()
method.
For example :
// convert number to big.Int type
ip := new(big.Int)
ip.SetString("338288524927261089654163772891438416681", 10) //base 10
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
+17k Golang : When to use init() function?
+6.6k Default cipher that OpenSSL used to encrypt a PEM file
+12.9k Golang : How to get a user home directory path?
+8.8k Golang : Intercept and compare HTTP response code example
+13.5k Golang : How to determine if a year is leap year?
+39.7k Golang : UDP client server read write example
+25k Golang : Convert uint value to string type
+30.9k Golang : bufio.NewReader.ReadLine to read file line by line
+6.2k Golang : Break string into a slice of characters example
+10.2k Golang : Generate random integer or float number
+10.2k Android Studio : Simple input textbox and intercept key example
+6.3k Golang : Embedded or data bundling example