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
+14.8k Golang : GUI with Qt and OpenCV to capture image from camera
+7.8k Javascript : Push notifications to browser with Push.js
+4.9k MariaDB/MySQL : Form select statement or search query with Chinese characters
+12.7k Golang : Forwarding a local port to a remote server example
+12k Golang : GTK Input dialog box examples
+5.9k Unix/Linux : Get reboot history or check when was the last reboot date
+6.8k Golang : When to use make or new?
+6.7k Golang : Warp text string by number of characters or runes example
+9.7k Golang : Quadratic example
+16.6k Golang : File path independent of Operating System
+31.7k Golang : Example for ECDSA(Elliptic Curve Digital Signature Algorithm) package functions