开发者

problem in unsigned long long in c++

i have a cpp file say xyz.cpp, which contains long constants. now i need to change long constants to long long.

ex   
long a=0x00000001

to

long long a=0x0000000000000001

for future purpose. ( i use gcc compiler ) But when i do so, i got "integer value is to large to hold the long value" error. when browsed over internet, i got a suggestion like use,

long long a=0x0000000000000001ULL .

that worked fine. but the problem is i ve a jar file, that need to convert this .cpp file to .java. when it try to convert a .java file from .cpp file, it does not recognizes ULL.

now my question is

1, to this scen开发者_运维百科erio, is this anyway for my gcc compiler to make accept long long values, instead of adding ULL @ the end 2, or suggest me what should i do in .java file to accept that long long value (ULL) ( i know java has only long value that can hold long long value )

thanks in advance :)


Since C++ won't compile as java without modifying the source, you could just strip the ULL/LL suffix (and change long long to long). You'll simply need to add this to the list of things to change when converting - I don't see the problem?


So, what exactly are you trying to do, convert C++ code to Java?

Java does not have unsigned integer types, and the "long long" type from C++ also does not exist in Java. Java has the following integer types:

byte - 8-bit signed integer

short - 16-bit signed integer

int - 32-bit signed integer

long - 64-bit signed integer

(There is also char, which is technically a 16-bit unsigned integer, but which is meant to hold character data).

You could use BigInteger in Java if you need to work with numbers that do not fit in a long.


long can hold 64-bits in Java, with signed behaviour where it matters. However this doesn't stop you storing unsigned 64-bit values in it. You need to write work arounds for certain operations, but +, -, *, == , != etc all work exactly the same.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜