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
+14.5k Golang : Record voice(audio) from microphone to .WAV file
+2k Javascript : Put image into Chrome browser's console
+8.1k Golang : Tutorial on loading GOB and PEM files
+8.5k Golang : How to get own program name during runtime ?
+2.5k Python : Delay with time.sleep() function example
+10.3k Golang : Use TLS version 1.2 and enforce server security configuration over client
+10.7k Golang : Simple client server example
+4.1k Golang : How to run your code only once with sync.Once object
+3.1k Golang : Error handling methods
+17.7k Golang : Check if element exist in map
+21k Get client IP Address in Go
+9.3k Golang : Get host name or domain name from IP address