Big Moose Saloon
 Search | Java FAQ | Recent Topics Register / Login

# [ask] how to calculate 128 bit number

alfonz jan frithz
Greenhorn

Joined: Apr 20, 2009
Posts: 20
hello guys, i just curious. how could i calculate a number that have more than 64 bit, let say 128 bit. Because as we know, the biggest primitive variable is long, which is 64 bit.

and if I calculate something, can i know how much time computers need/spend to calculate it?

thanks,, sorry for my english, im not english speaker anyway...
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9939

6

check out the BigInteger class.

Never ascribe to malice that which can be adequately explained by stupidity.
alfonz jan frithz
Greenhorn

Joined: Apr 20, 2009
Posts: 20
ok thank you... i understand then...
oh ya, another question, how could I know how much time computer spend to calculate certain operation...
thanks...
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16680

19

oh ya, another question, how could I know how much time computer spend to calculate certain operation...

This will be taught in your algorithms class.

And if you took algorithms already and don't recall. Remember that whole study on how an algorithm scales (big O notation)? Basically, once you figure out how something scales, you can take a few large samplings (but still tolerable in time) and from that, extrapolate how long it will take for an even larger calculation to take.

Henry

salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 915

To calculate time....

get the time in milliseconds before the calculation (say t1)
get the time in milliseconds after the calculation (say t2)

To know the time spent in milliseconds, calculate difference (say t2-t1)

My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32599

4
For many speed calculations the method in the System class which gives time in nanoseconds will be necessary. Even 1000000 operations will probably be too fast for the millisecond method to be accurate.

I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.

subject: [ask] how to calculate 128 bit number