I have a MAC address stored as a raw 48 bit number, and I want to split it up and print it in the standard hex format of xx:xx:xx:xx:xx:xx. For example, the raw number 81952921372024 should become 78:45:c4:26:89:4a. My first attempt was,
var suspect = {mac: 2333752735057272};
console.log(
Number(suspect.mac & 0xFF).toString(16) + ":" +
Number((suspect.mac & 0xFF00) >> 8).toString(16) + ":" +
Number((suspect.mac & 0xFF0000) >> 16).toString(16) + ":" +
Number((suspect.mac & 0xFF000000) >> 24).toString(16) + ":" +
Number((suspect.mac & 0xFF00000000) >> 32).toString(16) + ":" +
Number((suspect.mac & 0xFF0000000000) >> 48).toString(16));
But because Javascript apparently can't handle > 32 bit integers when doing shift operations, the last two octets always come out to 0,
78:45:c4:26:0:0