Created
June 7, 2014 10:25
-
-
Save dsaiztc/e722bbf2fc6136b03097 to your computer and use it in GitHub Desktop.
Convert an unsigned integer to signed (keeping binary value).
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
/** | |
* Convert an unsigned integer to signed (keeping binary value) | |
* | |
* @param binary Integer whose binary value need to convert | |
* @return A byte with same binary than income integer | |
*/ | |
private static byte fromBinaryToByte(int binary) | |
{ | |
byte result = -1; | |
String s = Integer.toBinaryString(binary); | |
result = (byte) Integer.parseInt(s, 2); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment