title: Meaning of %04X in C and how to write the same in java
body: <p>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.</p>
  
  <p>There is a statement in C code for printing to a file:</p>
  
  <pre><code>fprintf(ff, "%04X ", image[y*width+x]);
  </code></pre>
  
  <p>Firstly i am not sure about the meaning of <code>%04X</code>. I think it means that if <code>image[i]</code> has length five or more then print only leftmost four chararacters. To do the same in Java i thought about masking the value using <code>and</code> operation</p>
  
  <pre><code> image[i] &amp; 0xFFFF
  </code></pre>
  
  <p>Can someone please tell me the correct meaning of <code>%04X</code> and how to do the same in Java? Thanks.</p>