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
+12.6k Golang : Extract part of string with regular expression
+12.3k Golang : convert(cast) string to integer value
+6.9k Golang : Output or print out JSON stream/encoded data
+6.3k Golang : Build new URL for named or registered route with Gorilla webtoolkit example
+17.2k Golang : Get input from keyboard
+6.4k PHP : Get client IP address
+10.3k Golang : Find and replace data in all files recursively
+6.2k Golang : Function as an argument type example
+15k Golang : Reset buffer example
+38.6k Golang : Converting a negative number to positive number
+22.4k Golang : How to run Golang application such as web server in the background or as daemon?
+9.4k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)