Skip to content

Instantly share code, notes, and snippets.

@mmalecki
Created November 30, 2011 18:32
Show Gist options
  • Save mmalecki/1410174 to your computer and use it in GitHub Desktop.
Save mmalecki/1410174 to your computer and use it in GitHub Desktop.
Not really hex.
console.hex = function (data) {
var columns = 40,
line = '',
code;
function pad(number, length) {
var str = '' + number;
while (str.length < length) {
str = '0' + str;
}
return str;
}
for (var i = 0; i < data.length; i++) {
if ((i % columns) == 0) {
console.log(line);
line = '';
}
line += pad(data.charCodeAt(i), 3) + ' ';
}
console.log(line);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment