Java Utililty Methods Byte Create

List of utility methods to do Byte Create

Description

The list of methods to do Byte Create are organized into topic(s).

Method

bytetoByteFromBin(String binSymbols)
Transform a string of 8 bits into a byte
if (isValidBin(binSymbols) == false) {
    throw new IllegalArgumentException("Illegal characters in bin string");
binSymbols = stripBinaryPrefix(binSymbols);
if (binSymbols.length() > 8) {
    throw new IllegalArgumentException(
            "More than 8 bits in input bit string, cannot convert to a single byte");
while (binSymbols.length() != 8) {
    binSymbols = "0" + binSymbols;
byte bit0 = (byte) (((Integer.parseInt(binSymbols.substring(0, 1))) & 0x01) << 7);
byte bit1 = (byte) (((Integer.parseInt(binSymbols.substring(1, 2))) & 0x01) << 6);
byte bit2 = (byte) (((Integer.parseInt(binSymbols.substring(2, 3))) & 0x01) << 5);
byte bit3 = (byte) (((Integer.parseInt(binSymbols.substring(3, 4))) & 0x01) << 4);
byte bit4 = (byte) (((Integer.parseInt(binSymbols.substring(4, 5))) & 0x01) << 3);
byte bit5 = (byte) (((Integer.parseInt(binSymbols.substring(5, 6))) & 0x01) << 2);
byte bit6 = (byte) (((Integer.parseInt(binSymbols.substring(6, 7))) & 0x01) << 1);
byte bit7 = (byte) ((Integer.parseInt(binSymbols.substring(7, 8))) & 0x01);
return ((byte) (bit0 + bit1 + bit2 + bit3 + bit4 + bit5 + bit6 + bit7));
byte[][]toByteMatrix(Number[][] matrix)
Turns the Number matrix into one consisting of primitive bytes.
byte[][] result;
int i;
int n;
result = new byte[matrix.length][];
for (i = 0; i < matrix.length; i++) {
    result[i] = new byte[matrix[i].length];
    for (n = 0; n < matrix[i].length; n++)
        result[i][n] = matrix[i][n].byteValue();
...
BytetoByteObject(String value, Byte defaultValue)
to Byte Object
try {
    return new Byte(value);
} catch (Exception e) {
    return defaultValue;
StringtoByteUnit(long values)
to Byte Unit
double calcs = 0.0;
if (values == 0)
    return "0";
if (values == 1)
    return "1 byte";
if (values < 1024)
    return String.valueOf(values) + " bytes";
calcs = values / 1024.0;
...
bytetoByteValue(final int value)
Converts a signed or unsigned 8-bit integer into a byte.
checkByteValue(value);
return (byte) value;
bytetoByteWithoutOverflow(float value)
Like Math#toIntExact(long) but for byte range.
if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) {
    throw new ArithmeticException("byte overflow");
return (byte) value;