title: Reading Upper and Lower Bytes from Buffer with Node JS
body: <p>I'm screwing around and building a zip file reader in Node JS. I've encountered a point in the zip spec where I'm not quite sure how to proceed.</p>
  
  <p>I have a buffer that has two bytes containing data for <code>version made by</code>. There is an upper byte which tells which system the zip file was made by and there is a lower byte which tells which version of the zip spec was used to create the file.</p>
  
  <p>How do I read the upper byte and lower byte from the buffer? Right now my code is just doing:</p>
  
  <pre><code>var madeBy = buffer.readUInt16LE(4); // 4 is the offset of `version made by`
  </code></pre>
  
  <p>This unsigned integer ends up being a a number which I think is useless.</p>
  
  <p>Also, I don't know what upper/lower byte means, so if you could explain that to me that would also be helpful. :)</p>
  
  <hr>
  
  <p>For reference, here's a link to the documentation for Node JS buffers and also what the zip spec says:</p>
  
  <p><a href="https://nodejs.org/api/buffer.html" rel="nofollow">https://nodejs.org/api/buffer.html</a></p>
  
  <pre><code>4.4.2 version made by (2 bytes)
  
  4.4.2.1 The upper byte indicates the compatibility of the file
  attribute information.  If the external file attributes 
  are compatible with MS-DOS and can be read by PKZIP for 
  DOS version 2.04g then this value will be zero.  If these 
  attributes are not compatible, then this value will 
  identify the host system on which the attributes are 
  compatible.  Software can use this information to determine
  the line record format for text files etc.  
  
  4.4.2.2 The current mappings are:
  
   0 - MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems)
   1 - Amiga                     2 - OpenVMS
   3 - UNIX                      4 - VM/CMS
   5 - Atari ST                  6 - OS/2 H.P.F.S.
   7 - Macintosh                 8 - Z-System
   9 - CP/M                     10 - Windows NTFS
  11 - MVS (OS/390 - Z/OS)      12 - VSE
  13 - Acorn Risc               14 - VFAT
  15 - alternate MVS            16 - BeOS
  17 - Tandem                   18 - OS/400
  19 - OS X (Darwin)            20 thru 255 - unused
  
  4.4.2.3 The lower byte indicates the ZIP specification version 
  (the version of this document) supported by the software 
  used to encode the file.  The value/10 indicates the major 
  version number, and the value mod 10 is the minor version 
  number.  
  </code></pre>