code: public static byte[] str2bin(final String values, final JBBPBitOrder bitOrder) {
      if (values == null) {
        return new byte[0];
      }
  
      int buff = 0;
      int cnt = 0;
  
      final ByteArrayOutputStream buffer = new ByteArrayOutputStream((values.length() + 7) >> 3);
  
      final boolean msb0 = bitOrder == JBBPBitOrder.MSB0;
  
      for (final char v : values.toCharArray()) {
        switch (v) {
          case '_':
          case ' ':
            continue;
          case '0':
          case 'X':
          case 'x':
          case 'Z':
          case 'z': {
            if (msb0) {
              buff >>= 1;
            } else {
              buff <<= 1;
            }
          }
          break;
          case '1': {
            if (msb0) {
              buff = (buff >> 1) | 0x80;
            } else {
              buff = (buff << 1) | 1;
            }
          }
          break;
          default:
            throw new IllegalArgumentException("Detected unsupported char '" + v + ']');
        }
        cnt++;
        if (cnt == 8) {
          buffer.write(buff);
          cnt = 0;
          buff = 0;
        }
      }
      if (cnt > 0) {
        buffer.write(msb0 ? buff >>> (8 - cnt) : buff);
      }
      return buffer.toByteArray();
    }
docs: Convert string representation of binary data into byte array/
  
  @param values   a string represents binary data
  @param bitOrder the bit order to be used for operation
  @return a byte array generated from the decoded string, empty array for
  null string