Skip to content

Instantly share code, notes, and snippets.

@phoddie
Created June 4, 2018 22:46
Show Gist options
  • Save phoddie/647df056c10443cb7e1413f8df1ee736 to your computer and use it in GitHub Desktop.
Save phoddie/647df056c10443cb7e1413f8df1ee736 to your computer and use it in GitHub Desktop.
function tracePacket(bytes)
{
for (let i = 0; i < bytes.length; i += 16) {
let end = i + 16;
if (end > bytes.length) end = bytes.length;
for (let j = i; j < end; j++) {
let byte = bytes[j].toString(16);
if (byte.length < 2) byte = "0" + byte;
trace(byte, " ");
}
trace(" ");
for (let j = i; j < end; j++) {
let byte = bytes[j];
if ((32 <= byte) && (byte < 128))
trace(String.fromCharCode(byte));
else
trace(".");
}
trace("\n");
}
trace("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment