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
+43.7k Golang : Get hardware information such as disk, memory and CPU usage
+15k Golang : How to check for empty array string or string?
+26.9k Golang : Convert file content into array of bytes
+30k Golang : Get and Set User-Agent examples
+12.9k Golang : Convert IPv4 address to packed 32-bit binary format
+7.9k Golang : Example of how to detect which type of script a word belongs to
+11k Golang : Removes punctuation or defined delimiter from the user's input
+16.4k Golang : Find out mime type from bytes in buffer
+17k Golang : How to generate QR codes?
+16.2k Golang : How to check if input from os.Args is integer?
+40.7k Golang : Convert to io.ReadSeeker type