Skip to content

Instantly share code, notes, and snippets.

@esutton
Created October 19, 2018 19:49
Show Gist options
  • Save esutton/c000b912d2f5b0ef0d3cb132215cde23 to your computer and use it in GitHub Desktop.
Save esutton/c000b912d2f5b0ef0d3cb132215cde23 to your computer and use it in GitHub Desktop.
**
* Debug dump bytes in hexadecimal format 16-bytes per row
*
* 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
*
* @param {*} buffer
* @param {*} offsetStart
* @param {*} length
*/
function debugDumpHexBytes(buffer, offsetStart, length) {
let i = 0;
let row = 0;
console.log('------------------------');
while( length > i) {
let rowData = '';
for(let col = 0; col < 16; ++col ) {
if( length <= i ) {
break;
}
let spacer = ' ';
if( 7 === col ) {
spacer = ' ';
}
rowData = rowData + ('00' + buffer[i].toString(16)).substr(-2) + spacer;
++i;
}
console.log(('0000' + row.toString(16)).substr(-4) + ': ' + rowData);
row = row + 16;
}
console.log('------------------------');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment