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
+7.8k Golang : GMail API create and send draft with simple upload attachment example
+18.2k Golang : Example for DSA(Digital Signature Algorithm) package functions
+18.7k Golang : Accept input from user with fmt.Scanf skipped white spaces and how to fix it
+12.8k Golang : convert(cast) string to float value
+6k Golang : Null and nil value
+17.1k Golang : Logging with logrus
+9.4k Golang : Underscore string example
+11.4k Golang : zlib compress file example
+8.5k Golang : interface - when and where to use examples
+11.7k Android Studio : Password input and reveal password example
+12.5k Golang : Compress and decompress file with compress/flate example
+11.2k Golang : Validate email address