tags:

views:

275

answers:

7

can i represent 128 bit number in java? or in c++?

+6  A: 

In Java, you can use the BigInteger class to store arbitrarily large integers. In C++ you can use a library like GMP to get the same functionality.

MAK
+1 for listing BigInteger and a c++ library
Tim Bender
A: 

Write your own class and operations for representing 128 bit numbers or use some library available.

Prav
I can see why "write your own or don't write your own" was seen as less than helpful. Here is your chance for a 'Peer pressure' badge :)
David Sykes
A: 

The BigInteger class is designed for integer values bigger then Long.MAX_VALUE.

Andreas_D
+1  A: 

You can. You will most likely need to use a library to do this though, at least for C++.

I like the PolarSSL library or the GNU MP Bignum library.

samoz
+10  A: 

Of course you can represent them.

At least you can use a byte-array with 16 elements.

However, the question is if you just want to represent the value or actually do some calculations with it.

In Java you can use BigInteger to represent (effectively) arbitrary sized integer values and do calculations as well.

Joachim Sauer
A: 

java.math.BigInteger

To work with integers that are larger than 64 bits (the size of a long), use java.math.BigInteger. This class represents unbounded integers and provides a number of methods for doing arithmetic with them.

http://leepoint.net/notes-java/data/numbers/10biginteger.html

If you need decimal values use BigDecimal

Emperorlou
A: 

Of course, you can use BigInteger class in java.math package. This class provides operations for modular arithmetic, GCD calculation, primality testing, prime generation, bit manipulation like operations.

This class has been added in JDK1.1 itself.

But I don't know there is such a availability built into with C++ library. There can be a extensible API from third parties.

venJava