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
+35.2k Golang : Strip slashes from string example
+9k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference
+7.9k Golang : What fmt.Println() can do and println() cannot do
+10.4k Golang : Meaning of omitempty in struct's field tag
+7.5k Golang : Rename part of filename
+29.1k Golang : missing Git command
+6.1k Golang : Get missing location after unmarshal binary and gob decode time.
+8.5k Android Studio : Import third-party library or package into Gradle Scripts
+7.8k Golang Hello World Example
+6.2k Golang : Extract sub-strings
+17.9k Golang : How to log each HTTP request to your web server?
+35.8k Golang : Integer is between a range