/**/ public static void main(string[] strarr) { while (!BinaryStdIn.IsEmpty) { int ch = (int)BinaryStdIn.readChar(); BinaryStdOut.write((char)ch); } BinaryStdOut.flush(); }
private static Node readTrie() { boolean isLeaf = BinaryStdIn.readBoolean(); if (isLeaf) { return new Node(BinaryStdIn.readChar(), -1, null, null); } else { return new Node('\0', -1, readTrie(), readTrie()); } }
/** * Reads a binary sequence from standard input; converts each two bits * to an 8-bit extended ASCII character over the alphabet { A, C, T, G }; * and writes the results to standard output. */ public static void expand() { Alphabet DNA = Alphabet.DNA; int n = BinaryStdIn.readInt(); // Read two bits; write char. for (int i = 0; i < n; i++) { char c = BinaryStdIn.readChar(2); BinaryStdOut.write(DNA.toChar(c), 8); } BinaryStdOut.close(); }
/** * 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. * * @param args the command-line arguments */ 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"); }