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
+8.6k Golang : Bcrypting password
+11k Golang : How to parse plain email text and process email header?
+14.1k Golang : Intercept Ctrl-C interrupt or kill signal and determine the signal type
+6.8k Swift : Convert (cast) String to Double
+16k Golang : Iterate linked list example
+6.3k Javascript : Push notifications to browser with Push.js
+13.3k Golang : Submit web forms without browser by http.PostForm example
+8.4k Golang : Qt get screen resolution and display on center example
+5.7k Golang : How to fix html/template : "somefile" is undefined error?
+5.9k Golang : A simple forex opportunities scanner