Skip to content

Instantly share code, notes, and snippets.

@esutton
Last active July 20, 2022 20:18
Show Gist options
  • Select an option

  • Save esutton/e3dc0118f6033814da94fe5d547853e5 to your computer and use it in GitHub Desktop.

Select an option

Save esutton/e3dc0118f6033814da94fe5d547853e5 to your computer and use it in GitHub Desktop.

Revisions

  1. esutton revised this gist Jul 20, 2022. No changes.
  2. esutton revised this gist Jul 20, 2022. No changes.
  3. esutton created this gist Jul 20, 2022.
    40 changes: 40 additions & 0 deletions debugDumpHexBytes.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    /// Debug dump bytes in hexadecimal format 16-bytes per row
    ///
    /// \param source
    /// \param length
    ///
    /// Example Output:
    /// \code
    /// 0000 bd 7a 32 13 08 1c 1e d9 - c9 48 48 0b 5f 23 1a f5
    /// 0010 72 3d 8f 7a e6 2c 07 e4 - 6e 45 79 0f cb 18 13 6f
    /// \endcode
    void debugDumpHexBytes(const char* source, int length)
    {
    qDebug("------------------------");

    int offset = 0;
    int row = 0;
    QString line;
    while(length > offset )
    {
    line = QString::asprintf("%04x ", offset);

    for(int i = 0; i < 16; ++i)
    {
    if(8 == i)
    {
    line.append(" - ");
    }
    uint8_t value = source[offset++];
    line.append(QString::asprintf("%02x ", value));

    if(length == offset)
    {
    break;
    }
    }
    qDebug("%s", qPrintable(line));
    ++row;
    }
    qDebug("........................");
    }