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
+11.8k Golang : Find age or leap age from date of birth example
+13.4k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
+8.3k Golang : Get final or effective URL with Request.URL example
+6.9k Golang : Decode XML data from RSS feed
+15.8k Golang : Get checkbox or extract multipart form data value example
+5.1k Golang : micron to centimeter example
+4.2k Javascript : Empty an array example
+25.2k Golang : Create PDF file from HTML file
+6.9k Golang : Get expvar(export variables) to work with multiplexer
+17.8k Golang : Read data from config file and assign to variables
+7.3k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+18.7k Golang : Generate thumbnails from images