Does the JavaScript code
var n = 8; // or some arbitrary integer literal
n >> 1;
always denote "integer devision by 2 without remainer"? My concern is the endianess if the integer literal is larger than one byte.
The background of my question is the following:
I have an integer variable in the range from 0 to 2^32-1 that would fit into an uint32 if I had a typed programming language different than JS. I need to convert this into an Uint4Array with four elements in little endian order.
My current JavaScript approach is:
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 this would do everywhere. The principal idea is the fill the array by taking the LSB and divdiding by 256. But a real divions "/" would convert the variable into a floating point variable. So I use ">>8" but this actually assumes big endianness.