Created
October 19, 2018 19:49
-
-
Save esutton/c000b912d2f5b0ef0d3cb132215cde23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
** | |
* 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