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
+9k Golang : How to control fmt or log print format?
+7.5k Golang : Reverse a string with unicode
+22.2k Golang : Convert Unix timestamp to UTC timestamp
+6.4k Golang : Derive cryptographic key from passwords with Argon2
+13.5k Golang : unknown escape sequence error
+10.9k Golang : Intercept and process UNIX signals example
+6.9k CloudFlare : Another way to get visitor's real IP address
+6k Golang : How to get capacity of a slice or array?
+15.1k Golang : rune literal not terminated error
+26.3k Golang : Encrypt and decrypt data with AES crypto
+10k Golang : Convert file content to Hex