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
+3.2k Golang : Fix go-cron set time not working issue
+8.7k Golang : Find network service name from given port and protocol
+8k Golang : How To Use Panic and Recover
+7.8k Javascript : Put image into Chrome browser's console
+9.6k Golang : Turn string or text file into slice example
+10.8k Nginx : TLS 1.2 support
+27.5k PHP : Count number of JSON items/objects
+13.8k Golang : Fix cannot use buffer (type bytes.Buffer) as type io.Writer(Write method has pointer receiver) error
+7.1k Golang : Of hash table and hash map
+23.9k Golang : Upload to S3 with official aws-sdk-go package
+5.8k Golang : Function as an argument type example