doing math on arbitrarly large numbers

Hello,

I'm making an app which requires doing math on some arbitrary large numbers. Since math is usually my achilles heal, I have no idea how to do this.

Specifically, i have a byte[] number and I'm trying to implement these two functions:

byte[] root(byte[] number,int radix)

byte[] pow(byte[] base,int power)

can someone give me a clue on how to do this?

[397 byte] By [dfasdfsdafsadfasdfa] at [2007-11-26 18:03:41]
# 1
That depends on how the arbitrarly large numbers are represented in that byte-arrays of yours, we'd need more information to help here.Usually you use the existing BigInteger and/or BigDecimal classes for that kind of stuff.
JoachimSauera at 2007-7-9 5:33:54 > top of Java-index,Java Essentials,Java Programming...
# 2

> Hello,

> I'm making an app which requires doing math on some

> arbitrary large numbers. Since math is usually my

> achilles heal, I have no idea how to do this.

You mean Achilles heel? Apparently spelling isn't a strong suit, either.

> Specifically, i have a byte[] number and I'm trying

> to implement these two functions:

Who told you that a byte array would be a good way to go?

Ever thought about starting with arithmetic and working your way up?

What happened to abstraction? Shouldn't you create a class that hides the fact that you're using a byte array or something else?

> byte[] root(byte[] number,int radix)

Newton Raphson iteration is a good place to start for roots:

http://mathworld.wolfram.com/search/

> byte[] pow(byte[] base,int power)

If it's really an integer power, just loop "power" times and multiply the number by itself each time. Not too difficult.

%

duffymoa at 2007-7-9 5:33:54 > top of Java-index,Java Essentials,Java Programming...
# 3
alphabet,for chrisake google it... there are open source "libraries" in java to perform both these functions. it shouldn't take you more than 10 minutes to find both of them.why does everyone want to reinvent the square wheel all the time? sheesh!keith.
corlettka at 2007-7-9 5:33:54 > top of Java-index,Java Essentials,Java Programming...