I have a user type in addresses such as 0x20005c98, which i am calling in POST method using req.body.var
. However, I need this number in little endian so it shows 0x985c0020. Does anyone know how to convert this number to little endian in node js? Is there an easy way of doing this?? The network-byte-order npm is an option??
var n = 0x20005c98;
var s = n.toString(16)
var size = Math.ceil(s.length / 2) * 2;
while (s.length < size) s = "0" + s;
var data = s.match(/.{1,2}/g);
data.push("0x");
data.reverse().join("").toString(16); // ==> "0x985c0020" (= 2556166176)