13

In my use case, I would like to know how the following Java code would be implemented in Go

BigInteger base = new BigInteger("16");
int exponent = 1;
BigInteger a = base.pow(exponent); //16^1 = 16

I am able to import the math/big package and create big integers, but not able to do Pow() function in Go. Also I don't find the function in the Go doc.

Do I have to implement my own version of Pow() for bigint? Could anyone help me on this?

Rick-777
  • 9,714
  • 5
  • 34
  • 50
Dany
  • 2,692
  • 7
  • 44
  • 67

1 Answers1

29

Use Exp with m set to nil.

var i, e = big.NewInt(16), big.NewInt(2)
i.Exp(i, e, nil)
fmt.Println(i) // Prints 256

Playground: http://play.golang.org/p/0QFbNHEsn5

Ainar-G
  • 34,563
  • 13
  • 93
  • 119