Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>[edit 2018:]</strong> Re-wrote the function from scratch to make the code much more efficient and fix some other problems. You can now also optionally specify a starting offset and number of bytes (starting from there) to display.</p> <hr> <p>If you want the whole memory display, including the offset number, and left and right displays, you can do it like this: (32-byte width)</p> <pre><code>/// &lt;summary&gt; Returns a String where the specified bytes are formatted in a /// 3-section debugger-style aligned memory display, 32-bytes per line &lt;/summary&gt; public static unsafe String MemoryDisplay(byte[] mem, int i_start = 0, int c = -1) { if (mem == null) throw new ArgumentNullException(); if (i_start &lt; 0) throw new IndexOutOfRangeException(); if (c == -1) c = mem.Length - i_start; else if (c &lt; 0) throw new ArgumentException(); if (c == 0) return String.Empty; char* pch = stackalloc Char[32]; // for building right side at the same time var sb = new StringBuilder((c / 32 + 1) * 140); // exact pre-allocation c += i_start; for (int i = i_start &amp; ~0x1F; i &lt; c;) { sb.Append(i.ToString("x8")); sb.Append(' '); do { if (i &lt; i_start || i &gt;= c) // non-requested area, or past the end { sb.Append(" "); pch[i &amp; 0x1F] = ' '; } else { var b = mem[i]; sb.Append(b.ToString("x2") + " "); pch[i &amp; 0x1F] = non_monospace(b) ? '.' : (Char)b; } } while ((++i &amp; 0x1F) != 0); sb.Append(' '); sb.AppendLine(new String(pch, 0, 32)); } return sb.ToString(); } </code></pre> <p>The code uses the following helpers to determine which characters should be shown as 'dots' in right-hand part.</p> <pre><code>static readonly ulong[] _nmb = { 0x00000000ffffe7ffUL, 0x8000000000000000UL, 0x00002000ffffffffUL, 0x0000000000000000UL, }; static bool non_monospace(byte b) =&gt; (_nmb[b &gt;&gt; 6] &amp; 1UL &lt;&lt; b) != 0; </code></pre> <p>Output of the above function looks like this (character width is 138 columns, scroll to the right to see the "human-readable" part):</p> <pre> 00000000 47 49 46 38 39 61 0f 00 0f 00 91 ff 00 00 00 00 c0 c0 c0 ff ff 00 00 00 00 21 f9 04 01 00 00 01 GIF89a...................!...... 00000020 00 2c 00 00 00 00 0f 00 0f 00 00 02 2c 8c 0d 99 c7 91 02 e1 62 20 5a 79 ea bd 00 6d 89 69 8a f8 .,..........,.......b Zy...m.i.. 00000040 08 e5 a7 99 e9 17 9d ac 24 a2 21 68 89 1e ac b4 d9 db 51 ab da c8 8c 1a 05 00 3b ........$.!h......Q.......; </pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload