title: How to convert Node.js buffer to integer in the client-side?
body: <p>I'm trying to store an integer into a node.js buffer and then send it to the client-side via <a href="https://github.com/sandeepmistry/bleno" rel="nofollow noreferrer">bleno</a>:</p>
  
  <pre><code>var num = 24;
  var buf = new Buffer(1);
  buf.writeUInt8('0x' + num, 0);
  //send buf using bleno
  </code></pre>
  
  <p>I then convert this to a string in the client-side with the following code:</p>
  
  <pre><code>function bytesToString(buffer) {    
    return String.fromCharCode.apply(null, new Uint8Array(buffer));
  }
  </code></pre>
  
  <p>The problem is that I don't get the original value back (24). Instead what this returns is the '#' string.
  I also tried the solutions here: <a href="https://stackoverflow.com/questions/6965107/converting-between-strings-and-arraybuffers/9673053">Converting between strings and ArrayBuffers</a> but I either get chinese or unicode characters.</p>
  
  <p>Here's what I was doing previously in the Node.js side and it works without any problems with the bytesToString function above:</p>
  
  <pre><code>new Buffer(num.toString());
  </code></pre>
  
  <p>But the requirements specified that I should send the integer or float without converting it to string. Is this possible? Any ideas what I am doing wrong? Thanks in advance.</p>