Last active
November 18, 2020 23:33
-
-
Save icarus44-zer0/eeca1d24989b6defe38e6989a5b50a7e to your computer and use it in GitHub Desktop.
This file contains 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
private static void PUSHI(String dataHex) { | |
String builder = ""; | |
for (int i = 0; i < dataHex.length(); i++) { | |
switch (dataHex.substring(i, i + 1)) { | |
case "0": | |
builder += "0000"; | |
break; | |
case "1": | |
builder += "0001"; | |
break; | |
case "2": | |
builder += "0010"; | |
break; | |
case "3": | |
builder += "0011"; | |
break; | |
case "4": | |
builder += "0100"; | |
break; | |
case "5": | |
builder += "0101"; | |
break; | |
case "6": | |
builder += "0110"; | |
break; | |
case "7": | |
builder += "0111"; | |
break; | |
case "8": | |
builder += "1000"; | |
break; | |
case "9": | |
builder += "1001"; | |
break; | |
case "A": | |
builder += "1010"; | |
break; | |
case "B": | |
builder += "1011"; | |
break; | |
case "C": | |
builder += "1100"; | |
break; | |
case "D": | |
builder += "1101"; | |
break; | |
case "E": | |
builder += "1110"; | |
break; | |
case "F": | |
builder += "1111"; | |
break; | |
default: | |
break; | |
} | |
} | |
String sign = builder.substring(0, 1); | |
String sExt = ""; | |
if (sign.equals("1")) { | |
for (int i = builder.length(); i < 16; i++) { | |
sExt += "1"; | |
} | |
} else if (sign.equals("0")) { | |
for (int i = builder.length(); i < 16; i++) { | |
sExt += "0"; | |
} | |
} | |
builder = sExt + builder; | |
//System.out.println(builder); | |
String b2HEX = ""; | |
for (int i = 0 ; i < builder.length(); i+=4){ | |
switch (builder.substring(i, i + 4)) { | |
case "0000": | |
b2HEX += "0" ; | |
break; | |
case "0001": | |
b2HEX += "1"; | |
break; | |
case "0010": | |
b2HEX += "2"; | |
break; | |
case "0011": | |
b2HEX += "3"; | |
break; | |
case "0100": | |
b2HEX += "4"; | |
break; | |
case "0101": | |
b2HEX += "5"; | |
break; | |
case "0110": | |
b2HEX += "6"; | |
break; | |
case "0111": | |
b2HEX += "7"; | |
break; | |
case "1000": | |
b2HEX += "8"; | |
break; | |
case "1001": | |
b2HEX += "9"; | |
break; | |
case "1010": | |
b2HEX += "A"; | |
break; | |
case "1011": | |
b2HEX += "B"; | |
break; | |
case "1100": | |
b2HEX += "C"; | |
break; | |
case "1101": | |
b2HEX += "D"; | |
break; | |
case "1110": | |
b2HEX += "E"; | |
break; | |
case "1111": | |
b2HEX += "F"; | |
break; | |
default: | |
break; | |
} | |
} | |
// System.out.println(b2HEX); | |
short st = (short) Integer.parseInt(b2HEX, 16); | |
System.out.println(st); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment