Пример #1
0
  /**
   * Prints entries in a byte array as space separated hex values to {@link TTY}.
   *
   * @param address an address at which the bytes are located. This is used to print an address
   *     prefix per line of output.
   * @param array the array containing the bytes to print
   * @param offset the offset in {@code array} of the values to print
   * @param length the number of values from {@code array} print
   * @param bytesPerLine the number of values to print per line of output
   */
  public static void printBytes(
      long address, byte[] array, int offset, int length, int bytesPerLine) {
    assert bytesPerLine > 0;
    boolean newLine = true;
    for (int i = 0; i < length; i++) {
      if (newLine) {
        TTY.printf("%08x: ", address + i);
        newLine = false;
      }
      TTY.printf("%02x ", array[i]);
      if (i % bytesPerLine == bytesPerLine - 1) {
        TTY.println();
        newLine = true;
      }
    }

    if (length % bytesPerLine != bytesPerLine) {
      TTY.println();
    }
  }