[New] added ByteHelper.*nibble() methods

This commit is contained in:
Robert von Burg 2017-09-06 09:26:42 +02:00
parent d2f19dca5d
commit eaec58a223
1 changed files with 16 additions and 0 deletions

View File

@ -238,6 +238,22 @@ public class ByteHelper {
return (byte) (x ^ 0xff);
}
public static byte setLowerNibble(byte b, byte nibble) {
return (byte) ((b & ~(0xf)) | nibble);
}
public static byte setUpperNibble(byte b, byte nibble) {
return (byte) ((b & ~(0xf << 4)) | (nibble << 4));
}
public static byte getUpperNibble(byte b) {
return (byte) ((byte) (0xf0 & b) >> 4);
}
public static byte getLowerNibble(byte b) {
return (byte) (0xf & b);
}
/**
* Formats the given byte array to a binary string, separating each byte by a space
*