[Fix] ByteHelper.getUpperNibble() was broken for signed values

This commit is contained in:
Robert von Burg 2017-12-12 14:59:09 +01:00
parent 6328827f9e
commit 23007aae2f
1 changed files with 29 additions and 29 deletions

View File

@ -157,7 +157,7 @@ public class ByteHelper {
* byte
*
* @param bytes
* the bytes to convert to a long
* the bytes to convert to a long
*
* @return the long created from the bytes
*/
@ -181,7 +181,7 @@ public class ByteHelper {
* highest byte
*
* @param bytes
* the bytes to convert to an integer
* the bytes to convert to an integer
*
* @return the integer created from the bytes
*/
@ -201,7 +201,7 @@ public class ByteHelper {
* byte
*
* @param bytes
* the bytes to convert to an integer
* the bytes to convert to an integer
*
* @return the integer created from the bytes
*/
@ -247,18 +247,18 @@ public class ByteHelper {
}
public static byte getUpperNibble(byte b) {
return (byte) ((byte) (0xf0 & b) >> 4);
return (byte) (b >>> 4 & 0x0f);
}
public static byte getLowerNibble(byte b) {
return (byte) (0xf & b);
return (byte) (0x0f & b);
}
/**
* Formats the given byte array to a binary string, separating each byte by a space
*
* @param bytes
* the byte to format to a binary string
* the byte to format to a binary string
*
* @return the binary string
*/
@ -277,7 +277,7 @@ public class ByteHelper {
* Formats the given byte to a binary string
*
* @param b
* the byte to format to a binary string
* the byte to format to a binary string
*
* @return the binary string
*/
@ -301,7 +301,7 @@ public class ByteHelper {
* Formats the given integer to a binary string, each byte is separated by a space
*
* @param i
* the integer to format to a string
* the integer to format to a string
*
* @return the binary string
*/
@ -336,7 +336,7 @@ public class ByteHelper {
* Formats the given integer to a binary string, each byte is separated by a space
*
* @param i
* the integer to format to a string
* the integer to format to a string
*
* @return the binary string
*/
@ -393,7 +393,7 @@ public class ByteHelper {
* Formats the given long to a binary string, each byte is separated by a space
*
* @param i
* the long to format
* the long to format
*
* @return the binary string
*/