• 
    >scene
    =new Uint16Array(32)
    >scene[0]=0;
    =0
    >scene[1]=5000;
    =5000
    >scene[4]=44444;
    =44444
    >scene
    =new Uint16Array([0, 5000, 0, 0, 44444,  ... 0, 0, 0, 0, 0])
    >buff=new Uint8Array(64);
    =new Uint8Array(64)
    >E.toUint8Array(scene);
    =new Uint8Array([0, 136, 0, 0, 156,  ... 0, 0, 0, 0, 0]) //truncated
    >temp=new Uint8Array(64);
    =new Uint8Array(64)
    >temp.set(scene);
    =undefined
    >temp
    =new Uint8Array([0, 136, 0, 0, 156,  ... 0, 0, 0, 0, 0]) //truncated
    >E.toString(scene)
    ="\x00\x88\x00\x00\x9C\x00\x00\x00\x00\x­00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x­00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x­00\x00\x00" //truncated
    >temp = E.toUint8Array(E.toString(scene));
    =new Uint8Array([0, 136, 0, 0, 156,  ... 0, 0, 0, 0, 0])
    >temp=new Uint8Array(scene.buffer)
    =new Uint8Array([0, 0, 136, 19, 0,  ... 0, 0, 0, 0, 0]) //not truncated (what I expected the other things to do)
    
    

    Are those ones that truncate the values instead of splitting them up supposed to behave that way?

  • By truncating you mean producing an 8 bit number - turning 5000 into 136, rather than 19 and 136?

    I think so - E.toX takes whatever you give it, and should produce something with the same number of elements. I think if you did:

    a = new Uint16Array(4);
    a[1] = 4;
    b = E.toUint8Array(a);
    console.log(b[1]);
    

    You'd expect to get 4 returned.

    As you found, if you want to get at the untruncated byte data of a UintXArray, you can just access array.buffer

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

E.toString/E.toUint8Array - are these working correctly?

Posted by Avatar for DrAzzy @DrAzzy

Actions