title: Extract binary data from file in Perl
body: <p>I would like to extract date and time out of a binary file and convert it to ASCII in Perl.
  <img src="https://i.stack.imgur.com/yr4NM.jpg" alt="hex dump"></p>
  
  <p>How do I convert the binary data into an integer and into ASCII characters?</p>
  
  <p>I have tried the code below, but it seems like I can only print out the first two bytes and then I only see zeroes for the next iterations. Occasionally, I do get other values, but it seems like I am not doing the conversion correct and missing some information.</p>
  
  <blockquote>
  <pre><code> while (( $n = read FILE, $data, 4) != 0 ) {
  </code></pre>
    
    <blockquote>
  <pre><code>  my $hex = sprintf('%04X', ord($data))
  </code></pre>
      
      <p>}</p>
    </blockquote>
  </blockquote>
  
  <p>Is there some kind of conversion to integer that must take place?
  How do I convert this correctly?</p>
  
  <p>Edit: In the hex dump I need to convert 04FF into an integer.</p>