code: static String byteToBinaryString(byte b, int limit) {
      final StringBuilder sb = new StringBuilder();
      if (limit > 8) {
        limit = 8;
      }
      for (int i = 0; i < limit; i++) {
        sb.append((char)('0' + (b&1)));
        b>>=1;
      }
      return sb.toString();
    }
docs: Converts a byte into its binary representation (with at most 8 digits).
  @param b  the byte to be converted
  @param limit  the maximal length of returned string - it will never exceed 8 anyway
  @return binary representation, lowest bit (weight 1) goes first