Is JavaScript code
var n = 8; // or some arbitrary integer literal n >> 1;
always mean "integer allotment of 2 with no remainder"? My concern is endianess if the integer literal is more than one byte.
The background of my question is this:
I have an integer variable ranging from 0 to 2 ^ 32-1 that will fit in uint32 if I had a typed programming language other than JS. I need to convert this to a Uint4Array with four elements in a small trailing order.
My current JavaScript approach:
function uInt32ToLEByteArray( n ) { var byteArray = new Uint8Array(4); for( var i = 0; i < 4; i++ ) { byteArray[i] = n & 255; n >> 8; } return byteArray; }
This code works in my browser, but I wonder if it will do it everywhere. The main idea is to fill the array by taking LSB and dividing it by 256. But real divs "/" convert the variable to a floating point variable. Therefore, I use "β 8", but in fact it assumes greater reliability.
source share