title: python struct.unpack in Java
body: <p>I am pretty new to Python and have been trying to port a python script in Java.
  For a while I have been stuck at the following code logic, trying to convert it to Java but have been unable to do so (probably because I misunderstood what's actually being done)</p>
  
  <pre><code>data = unpack('&gt;H', file.read(2))
  if data == 0xffff
  then //do something
  else //do something else
  </code></pre>
  
  <p>now, this is I think is being done in the python script above:-
  unpacking a string (I believe, reading first 2 bytes of a file) in hexa-decimal format and then checking if it is value is 0)</p>
  
  <p>Is my perception about unpacking correct ; if not, then what's exactly unpacking doing? Is it getting a substring from the file object via this operation:- </p>
  
  <p>1 - read the file into a byte array</p>
  
  <p>2 - get the first 2 elements of the byte array</p>
  
  <p>then doing what?</p>
  
  <p>Can someone please help me write down the logic as mentioned in python above in Java?</p>