Byte Format
@param  Integer
@param  Integer
@return String
489675
public static function bytesFormat($size, $precision = 2)
    {
        $base = log($size) / log(1024);
        $suffix = array('', 'KB', 'MB', 'GB', 'TB');

        return round(pow(1024, $base - floor($base)), $precision) . $suffix[floor($base)];
    }
1223553
@SuppressWarnings("empty-statement")
    public static String decodeIntegerToString(BigInteger num) {
        byte[] bytes = num.toByteArray();
        int count;
        for (count = 0; count < bytes.length && bytes[count] == 0; count++);
        byte[] trimmed = new byte[bytes.length - count];
        System.arraycopy(bytes, count, trimmed, 0, trimmed.length);
        return new String(trimmed, StandardCharsets.UTF_8);
    }
1029191
public static int readInt(byte[] bytes, int offset) {
        return (((bytes[offset + 0] & 0xff) << 24) | ((bytes[offset + 1] & 0xff) << 16)
                | ((bytes[offset + 2] & 0xff) << 8) | (bytes[offset + 3] & 0xff));
    }
768438
public static String byte2FitMemorySize(final long byteNum) {
        if (byteNum < 0) {
            return "shouldn't be less than zero!";
        } else if (byteNum < MemoryConst.KB) {
            return String.format("%.3fB", (double) byteNum);
        } else if (byteNum < MemoryConst.MB) {
            return String.format("%.3fKB", (double) byteNum / MemoryConst.KB);
        } else if (byteNum < MemoryConst.GB) {
            return String.format("%.3fMB", (double) byteNum / MemoryConst.MB);
        } else {
            return String.format("%.3fGB", (double) byteNum / MemoryConst.GB);
        }
    }
1188351
public function parseInteger(string $integer): ?int
    {
        if (array_key_exists($integer, $this->bitAliases)) {
            return $this->bitAliases[$integer];
        }
        if ($integer === 'null') return null;
        if (strpos($integer, '0b') === 0) {
            return (int)base_convert($integer, 2, 10);
        }
        return (int)$integer;
    }
268433
public static void writeInt(byte[] bytes, int value, int offset) {
        bytes[offset] = (byte) (0xFF & (value >> 24));
        bytes[offset + 1] = (byte) (0xFF & (value >> 16));
        bytes[offset + 2] = (byte) (0xFF & (value >> 8));
        bytes[offset + 3] = (byte) (0xFF & value);
    }
408982
public byte getByte(int index)
    {
        checkPositionIndexes(index, index + SIZE_OF_BYTE, this.length);
        index += offset;
        return data[index];
    }
274814
public static String toHex(byte[] bytes) {
		StringBuilder hexString=new StringBuilder();
		for (int i=0; i<bytes.length; i++) {

			String hex=Integer.toHexString(0xFF & bytes[i]);
			if (hex.length() == 1) {
				hexString.append('0');
			}

			hexString.append(hex);
		}

		return hexString.toString();
	}
1031954
public static int bytesToInt(final byte[] arr) {
    int v = 0;
    for (int i = 0; i < 4; i++) {
      v |= (arr[i] & 0XFF) << (i * 8);
    }
    return v;
  }
1124812
def int_to_padded_hex_byte(integer):
    
    to_hex = hex(integer)
    xpos = to_hex.find('x')
    hex_byte = to_hex[xpos+1 : len(to_hex)].upper()

    if len(hex_byte) == 1:
        hex_byte = ''.join(['0', hex_byte])

    return hex_byte
792689
public static function formatSizeUnits($bytes)
    {
        if ($bytes >= 1073741824) {
            $bytes = number_format($bytes / 1073741824, 2) . ' GB';
        } elseif ($bytes >= 1048576) {
            $bytes = number_format($bytes / 1048576, 2) . ' MB';
        } elseif ($bytes >= 1024) {
            $bytes = number_format($bytes / 1024, 2) . ' KB';
        } elseif ($bytes > 1) {
            $bytes = $bytes . ' bytes';
        } elseif ($bytes === 1) {
            $bytes = $bytes . ' byte';
        } else {
            $bytes = '0 bytes';
        }

        return $bytes;
    }
383876
private static String byteToHexString(byte[] bytes)
  {
    final char[] hexArray = "0123456789ABCDEF".toCharArray();
    char[] hexChars = new char[bytes.length * 2];
    for (int j = 0; j < bytes.length; j++)
    {
      int v = bytes[j] & 0xFF;
      hexChars[j * 2] = hexArray[v >>> 4];
      hexChars[j * 2 + 1] = hexArray[v & 0x0F];
    }
    return new String(hexChars);
  }
505187
function intToBytes(num) {
	var bytes = [];

	for(var i=7 ; i>=0 ; --i) {
		bytes[i] = num & (255);
		num = num >> 8;
	}

	return bytes;
}
953182
public static byte[] toBytes(UUID id) {
    byte[] bytes = new byte[16];
    ByteUtils.writeLong(id.getMostSignificantBits(), bytes, 0);
    ByteUtils.writeLong(id.getLeastSignificantBits(), bytes, 8);
    return bytes;
  }
482236
private static byte[] intToByteArray(int value)
    {
        byte[] data = new byte[4];

        // int -> byte[]
        for (int i = 0; i < 4; ++i)
        {
            int shift = i << 3; // i * 8
            data[3 - i] = (byte) ((value & (0xff << shift)) >>> shift);
        }
        return data;
    }
958326
public static function formatByte($byte)
    {
        // ignore "Warning: Division by zero"
        if ($byte == 0) {
            return '0 B';
        }
        $s = array('B', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb');
        $e = floor(log($byte)/log(1024));
        return sprintf('%.2f '.$s[$e], ($byte/pow(1024, floor($e))));
    }
771502
public static String toHex(byte[] bytes) {
    StringBuffer buffer = new StringBuffer();

    for (byte b : bytes) {
      buffer.append(String.format("%02X", b));
    }

    return buffer.toString();
  }