Skip to content

Instantly share code, notes, and snippets.

@billywhizz
Created October 14, 2010 19:22
Show Gist options
  • Save billywhizz/626844 to your computer and use it in GitHub Desktop.
Save billywhizz/626844 to your computer and use it in GitHub Desktop.
Buffer.prototype.pprint = function() {
var line = "";
if(this.length > 0) {
for(var i=0; i<this.length; i++) {
if(i%8==0) {
sys.print(" ");
}
if(i%16==0) {
sys.print(line);
line = "";
sys.print("\n");
var ss = "00000000" + i.toString(10);
sys.print(ss.slice(ss.length - 8) + ": ");
}
if(this[i] > 15) {
sys.print(this[i].toString(16) + " ");
}
else {
sys.print("0" + this[i].toString(16) + " ");
}
if(this[i] >= 0x20 && this[i] <= 0x7e) {
line += String.fromCharCode(this[i]);
}
else {
line += ".";
}
}
sys.print("\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment