示例#1
0
  public static void main(String[] args) {
    int BITS_PER_LINE = 16;
    if (args.length == 1) {
      BITS_PER_LINE = Integer.parseInt(args[0]);
    }

    int count;
    for (count = 0; !BinaryStdIn.isEmpty(); count++) {
      if (BITS_PER_LINE == 0) {
        BinaryStdIn.readBoolean();
        continue;
      } else if (count != 0 && count % BITS_PER_LINE == 0) StdOut.println();
      if (BinaryStdIn.readBoolean()) StdOut.print(1);
      else StdOut.print(0);
    }
    if (BITS_PER_LINE != 0) StdOut.println();
    StdOut.println("Liczba bitow: " + count);
  }
示例#2
0
 public static void main(String[] args) {
   int width = Integer.parseInt(args[0]);
   int height = Integer.parseInt(args[1]);
   Picture pic = new Picture(width, height);
   int count = 0;
   for (int i = 0; i < height; i++) {
     for (int j = 0; j < width; j++) {
       pic.set(j, i, Color.RED);
       if (!BinaryStdIn.isEmpty()) {
         count++;
         boolean bit = BinaryStdIn.readBoolean();
         if (bit) pic.set(j, i, Color.BLACK);
         else pic.set(j, i, Color.WHITE);
       }
     }
   }
   pic.show();
   StdOut.println(count + " bits");
 }
示例#3
0
  /**
   * Reads in a sequence of bytes from standard input and writes them to standard output using
   * hexademical notation, k hex digits per line, where k is given as a command-line integer
   * (defaults to 16 if no integer is specified); also writes the number of bits.
   */
  public static void main(String[] args) {
    int bytesPerLine = 16;
    if (args.length == 1) {
      bytesPerLine = Integer.parseInt(args[0]);
    }

    int i;
    for (i = 0; !BinaryStdIn.isEmpty(); i++) {
      if (bytesPerLine == 0) {
        BinaryStdIn.readChar();
        continue;
      }
      if (i == 0) StdOut.printf("");
      else if (i % bytesPerLine == 0) StdOut.printf("\n", i);
      else StdOut.print(" ");
      char c = BinaryStdIn.readChar();
      StdOut.printf("%02x", c & 0xff);
    }
    if (bytesPerLine != 0) StdOut.println();
    StdOut.println((i * 8) + " bits");
  }