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
+20.7k Nginx + FastCGI + Go Setup.
+6.2k Golang : Scan forex opportunities by Bollinger bands
+8k Swift : Convert (cast) String to Float
+12.8k Golang : flag provided but not defined error
+6.8k Golang : Experimental emojis or emoticons icons programming language
+5.5k Python : Delay with time.sleep() function example
+19.7k Golang : Close channel after ticker stopped example
+38.2k Golang : Converting a negative number to positive number
+7.3k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+16.5k Golang : Test floating point numbers not-a-number and infinite example
+7.8k Golang : Convert(cast) io.Reader type to string
+7k How to let Facebook Login button redirect to a particular URL ?