programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# [ask] how to calculate 128 bit number

Alfonsus Hartanto
Greenhorn
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
Posts: 12563
49
check out the BigInteger class.

Alfonsus Hartanto
Greenhorn
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
Posts: 23295
125
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
Bartender
Posts: 1653
37
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)

Campbell Ritchie
Marshal
Posts: 56540
172
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.