In the java project i am working on, some portion of the project was written previously by someone else in C and now i need to write the same in Java.
There is a statement in C code for printing to a file:
fprintf(ff, "%04X ", image[y*width+x]);
Firstly i am not sure about the meaning of %04X. I think it means that if image[i] has length five or more then print only leftmost four chararacters. To do the same in Java i thought about masking the value using and operation
image[i] & 0xFFFF
Can someone please tell me the correct meaning of %04X and how to do the same in Java? Thanks.
The value is formatted as a hexadecimal integer with four digits and leading zeros. Java uses the same format string syntax. You can find it in the javaDoc of
Formatter.Excerpt:
A related functions are
(*) – write it to the
PrintStreamSystem.outwhich is usually the console but can be redirected to a file or something else