String formatting options

180 views Asked by At

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.

1

There are 1 answers

0
Chandrayya G K On BEST ANSWER

Try this:

BigInteger in = new BigInteger("FFFFFFFFFFFFFFFF", 16);        
System.out.println(String.format("%.8s", String.format("%x", in)));