Created
March 31, 2015 23:53
-
-
Save NicMcPhee/49d7a597e8d8c1e25ab8 to your computer and use it in GitHub Desktop.
A little example showing how to convert Java's signed bytes to the appropriate unsigned integer value.
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
public class ConvertingSignedBytes { | |
public static void main(String[] args) { | |
byte x = (byte) 37; | |
byte y = (byte) 150; | |
printByte(x); | |
printByte(y); | |
} | |
public static void printByte(byte b) { | |
int value; | |
if (b < 0) { | |
value = 256 + b; | |
} else { | |
value = b; | |
} | |
System.out.println(value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment