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
+18.6k Golang : Set or Add HTTP Request Headers
+18.2k Golang : Compare floating-point numbers
+6.1k Nginx : How to block user agent ?
+3.5k Java : Generate multiplication table example
+10k Golang : Fix fmt.Scanf() on Windows will scan input twice problem
+6.9k Golang : Get all countries phone codes
+8.2k Golang : does not implement flag.Value (missing Set method)
+12.4k Golang : Activate web camera and broadcast out base64 encoded images
+5.1k Javascript : Get operating system and browser information
+7.9k Golang : automatically figure out array length(size) with three dots
+28.9k Golang : Calculate percentage change of two values
+12.2k Golang : Get dimension(width and height) of image file