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
+9.9k Golang : Simple Jawi(Yawi) to Rumi(Latin/Romanize) converter
+21.6k Golang : Convert seconds to minutes and remainder seconds
+10.3k Android Studio : Checkbox for user to select options example
+5.3k Python : Print unicode escape characters and string
+7.7k Golang : Get all countries phone codes
+8.2k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared
+9k Golang : Launch Mac OS X Preview (or other OS) application from your program example
+4.8k Python : Create Whois client or function example
+18.9k Golang : Delete item from slice based on index/key position
+16.7k Golang : How to save log messages to file?
+9.6k Golang : Sort and reverse sort a slice of integers