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
+31k error: trying to remove "yum", which is protected
+6.3k Golang : Get missing location after unmarshal binary and gob decode time.
+26.1k Golang : How to read integer value from standard input ?
+9.2k Golang : Handle sub domain with Gin
+12.1k Golang : Convert a rune to unicode style string \u
+9.7k Android Studio : Indicate progression with ProgressBar example
+8.1k Golang : Ways to recover memory during run time.
+9.3k Golang : Simple histogram example
+26.6k Golang : Get executable name behind process ID example
+19.2k Golang : Clearing slice
+6.2k PageSpeed : Clear or flush cache on web server
+18.7k Golang : Send email with attachment