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 PHP : Proper way to get UTF-8 character or string length
+8.4k Golang : Ackermann function example
+10.1k Golang : How to tokenize source code with text/scanner package?
+5.6k Fix fatal error: evacuation not done in time problem
+9.6k Golang : Quadratic example
+13.8k Golang : Human readable time elapsed format such as 5 days ago
+36.2k Golang : Save image to PNG, JPEG or GIF format.
+19.3k Golang : How to count the number of repeated characters in a string?
+27.6k PHP : Count number of JSON items/objects
+11.5k Golang : Display a text file line by line with line number example
+7.8k Swift : Convert (cast) String to Double
+31.8k Golang : Convert an image file to []byte