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
+5k JavaScript/JQuery : Redirect page examples
+14.1k Golang : How to filter a map's elements for faster lookup
+22.7k Golang : Read a file into an array or slice example
+5.3k Python : Print unicode escape characters and string
+3.5k Java : Random alphabets, alpha-numeric or numbers only string generator
+7.9k Golang : Get final or effective URL with Request.URL example
+5.8k Fix ERROR 2003 (HY000): Can't connect to MySQL server on 'IP address' (111)
+6.3k Golang : Combine slices of complex numbers and operation example
+9.1k Golang : Detect Pascal, Kebab, Screaming Snake and Camel cases
+8.9k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
+17.7k Golang : How to log each HTTP request to your web server?
+7.1k Golang : Word limiter example