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
+18.3k Golang : How to force compile or remove object files first before rebuild?
+6.7k Golang : Variadic function arguments sanity check example
+7.9k Golang : How to control fmt or log print format?
+3.5k Python : Find out the variable type and determine the type with simple test
+12.5k Golang : Check if a file exist or not
+6.6k Golang : Handle Palindrome string with case sensitivity and unicode
+9.9k Golang : Sort and reverse sort a slice of runes
+4.2k Golang : Intercept, inject and replay HTTP traffics from web server
+20.5k Golang : untar or extract tar ball archive example
+17.7k Android Studio : AlertDialog and EditText to get user string input example