Created
April 11, 2013 17:57
-
-
Save gogromat/5365650 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// creates a binary Array Buffer | |
// (нельзя просмотреть просто так, нужен ArrayBufferView) | |
var buffer = new ArrayBuffer(10), | |
// (unsigned = capable of representing only non-negative integers [0,oo) ) | |
ex = new Uint8Array(buffer); | |
// Ex. Size 8-bit (Uint8Array) | |
// 0 0 0 0 0 0 0 0 | |
// 128 64 32 16 8 4 2 1 [low=0|high=255|total=256] | |
console.log("Unsigned 8-bit view:", ex); // [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, func... | |
ex[0] = NaN; //0 | |
ex[1] = undefined; //0 | |
ex[2] = null; //0 | |
ex[3] = "cat"; //0 | |
ex[4] = 18; | |
ex[5] = 255; | |
ex[6] = 510; //255,0,254 => 254 | |
ex[7] = 1024; //255,0,255,0,255,0,255,0 => 0 (1020(4x255)+4(0)) | |
ex[8] = 0; | |
ex[9] = ex[5]+ex[6]; //255,254-1(0)[253] => 253 | |
console.log("Unsigned 8-bit Array:", ex); // 0, 0, 0, 0, 18, 255, 254, 0, 0, 253, func... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment