title: How to convert Bigtable HBase API returning byte array to integer or float in nodeJS?
body: <p>I am writing data from dataflow into bigtable, and need to retrieve data from NodeJS, but realised that the data is in byte array. How do I convert back to integer or float? </p>
  
  <p>The key "\u0000\u0000\u0000\u0000" was originally a 0, but I could never get it to output correctly in my nodeJS code.</p>
  
  <p>I have tried the below methods using Buffer, bin2string, byteArrayToLong, but none of them worked correctly. The following is the code to query data.</p>
  
  <pre><code>async function query(table, start, end) {
    return new Promise((resolve, reject) =&gt; {
      table.createReadStream({
        start: start,
        end: end
      }).on('data', function(row) {
          for(var key in row.data.ch){
              console.log(JSON.stringify(key));               // Output: "\u0000\u0000\u0000\u0000"
              console.log(`bin2string: ${bin2string(key)}`);  // Output: bin2string:
  
              let keybuf = Buffer.from(key);
              console.log(keybuf);                            // Output: &lt;Buffer 00 00 00 00&gt;
              console.log(keybuf.toString('utf8'));           // Output:
              const utf16Buffer = Buffer.from(key,'utf16le'); // Output: &lt;Buffer 00 00 00 00 00 00 00 00&gt;
              console.log(utf16Buffer);
              console.log(utf16Buffer.toString());            // Output:
              console.log(byteArrayToLong(key));              // Output: NaN
          }
        // Nothing to do with data
        // We can measure the time needed to get the first row
      }).on('end', function(){
        resolve();
      });  
    });
  }
  
  function bin2string(array){
      var result = "";
      for(var i = 0; i &lt; array.length; ++i){
          result+= (String.fromCharCode(array[i]));
      }
      return result;
  }
  
  function byteArrayToLong (byteArray){
      var value =0;
      for(var i=byteArray.length-1; i&gt;=0; i--){
          value = value*256 + byteArray[i];
      }
      return value;
  }
  </code></pre>