开发者

C stroull equivalent in Java

开发者 https://www.devze.com 2023-04-01 00:53 出处:网络
I have a Objective C code,which I have to translate in Java,but I have a little problem with converting one line. In Objective C code I have : UInt64 iz = strtoull(s,&s1,16);. I was searching over

I have a Objective C code,which I have to translate in Java,but I have a little problem with converting one line. In Objective C code I have : UInt64 iz = strtoull(s,&s1,16);. I was searching over the internet abotu strtoull and I find this information for it :

strtoul will convert a string to an unsigned long integer. An important feature of this function is the ability to accept data in various number bases and convert to decimal.

The first argument must not contain a + or -. The second argument (char **endptr) seems to be a waste of space! If it is set to NULL, STRTOL seems to work its way down the string until it finds an invalid character and then stops. All valid chars read are then converted if the string starts with an invalid character the function returns ZERO (0).

The Third argument (base) can have a value of 0 or 2-32.

0 - strtol will attempt to pick the base. Only Dec, Oct Hex supported. 2-31 - The base to use.

I tried to find a way to do this in Java.As a made some researches I got this :

long l=Long.parseLong(md5Hash, 16);

And my question is,is parseLong equivalent to strtoull and can I use it for my applicati开发者_如何学JAVAon? If not can you suggest me what can I use?

Thanks in advance!


You can't because long is signed in Java. If you need unsigned integers for the full value range of 64 Bit then you have to use the BigInteger class.


Long.parseLong is the usual way of parsing a string into a long. But be aware that Java does not have unsigned types.


It is equivalent but keep in mind that long in Java is not unsigned. Therefore, a Java long is in [-2^63, 2^63 - 1].


use BigInteger(String val, int radix)

0

精彩评论

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