Created
February 22, 2019 15:04
-
-
Save RedDragon55/00bb3b54d468da70de957f30dc16f379 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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