You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • @DrAzzy yes, and you can actually do it on an existing buffer, so for instance:

    var a=new Uint8Array(12);
    var f = new Float32Array(a.buffer,0,2);
    f[0] = ...;
    f[1] = ...;
    (new Uint32Array(a.buffer,8,1))[0] = ...;
    console.log(a);
    

    I guess you could do:

    AT24.prototype.aToN=function(a){return (new Uint32Array((new Uint8Array(a)).buffer))[0];}
    

    And another nice one - although you don't use sToA:

    function stoA(s) {
      var a = new Uint8Array(s.length);
      a.set(s); // I don't think passing a string into set is standard JS though!
      return a;
    }
    
About

Avatar for Gordon @Gordon started