JSFiddle - React, Tailwind, and code Playground
JavaScript
var str = "45035997012373300";
var bytes = new Array(7);
for(var k=0;k<8;k++) {
bytes[k] = mod256(str);
str = divide256(str);
}
console.log(bytes);
function divide256(n)
{
if (n.length <= 8)
{
return (Math.floor(parseInt(n) / 256)).toString();
}
else
{
var top = n.substring(0, n.length - 8);
var bottom = n.substring(n.length - 8);
var topVal = Math.floor(parseInt(top) / 256);
var bottomVal = Math.floor(parseInt(bottom) / 256);
var rem = (100000000 / 256) * (parseInt(top) % 256);
bottomVal += rem;
topVal += Math.floor(bottomVal / 100000000);
bottomVal %= 100000000;
if (topVal == 0) return bottomVal.toString();
else return topVal.toString() + bottomVal.toString();
}
}
function mod256(n)
{
if (n.length <= 8)
{
return parseInt(n) & 255;
}
else
{
return parseInt(n.substring(n.length - 8)) & 255;
}
}