Equivalent of _byteswap_ulong in JavaScript/Node.js? -


what equivalent of _byteswap_ulong in javascript?

i'm using following c++ code:

int tag = 2832779; tag = _byteswap_ulong(tag) >> 8; 

the result of tag 9124193.

i tried doing same in javascript:

var tag = 2832779; tag = (((tag >> 24) & 0x000000ff) | ((tag >> 8) & 0x0000ff00) | ((tag << 8) & 0x00ff0000) | ((tag << 24) & 0xff000000)) >> 8; 

however, result of tag (in js) -7653077.

is possible swap bytes in javascript same way it's possible in c++?

thanks lot!

assuming meant 9124139, here simple function should work:

function byteswap(n) {   n = n.tostring(16);   if ((n.length % 2) !== 0)     n = '0' + n;   return parseint(n.match(/([a-z0-9]{2})/g).reverse().join(''), 16); }  console.log(byteswap(2832779)); // outputs: 9124139 

Comments