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
+6.3k Apt-get to install and uninstall Golang
+13.5k Golang : Verify token from Google Authenticator App
+9.1k Golang : Get curl -I or head data from URL example
+5.2k Python : Create Whois client or function example
+8.2k Golang : Qt splash screen with delay example
+12.2k Golang : calculate elapsed run time
+16.3k Golang : convert string or integer to big.Int type
+7.9k Golang : Get today's weekday name and calculate target day distance example
+27.5k Golang : Convert integer to binary, octal, hexadecimal and back to integer
+6.6k Elasticsearch : Shutdown a local node
+16.5k Golang : Check if a string contains multiple sub-strings in []string?