Question

I am porting a C code to xtend, and I have an 32bit integer. Since Java's Integer has a maximum value of 0x7FFFFFFF, I decided to use Long because I would need 0xFFFFFFFF.

When I print it out,

Long value = 0xFFFFFFFFFFFFFFFF;
String::Format("0x%08X", value);

I am getting the output: 0xFFFFFFFFFFFFFFFF. I am expecting to only get 0xFFFFFFFF. To get rid of the leading Fs, I tried doing this:

value.bitwiseAnd(0x00000000FFFFFFFF)

But the output is still the same. How can I format it in String::Format such that it will not display the the first FFFFFFFF? I only need the lower 32bits.

Was it helpful?

Solution

Try this:

BigInteger in = new BigInteger("FFFFFFFFFFFFFFFF", 16);        
System.out.println(String.format("%.8s", String.format("%x", in)));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top