Skip to content

Instantly share code, notes, and snippets.

@RedDragon55
Created February 22, 2019 15:04
Show Gist options
  • Select an option

  • Save RedDragon55/00bb3b54d468da70de957f30dc16f379 to your computer and use it in GitHub Desktop.

Select an option

Save RedDragon55/00bb3b54d468da70de957f30dc16f379 to your computer and use it in GitHub Desktop.
function ToInteger(x) {
x = Number(x);
return x < 0 ? Math.ceil(x) : Math.floor(x);
}
function modulo(a, b) {
return a - Math.floor(a/b)*b;
}
function ToUint8(x) {
return modulo(ToInteger(x), Math.pow(2, 8));
}
function ToInt8(x) {
var uint8 = ToUint8(x);
if (uint8 >= Math.pow(2, 7)) {
return uint8 - Math.pow(2, 8)
} else {
return uint8;
}
}
console.log(ToInt8(parseInt("80", 16)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment