Last active
December 25, 2015 18:19
-
-
Save jarrodbell/7019329 to your computer and use it in GitHub Desktop.
Convert byte array (or string) to a readable "\xFF" formatted string for any bytes outside the printable ascii range (32-127 decimal)
This file contains hidden or 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
function makeReadable(bytes) { | |
var readable = "", i; | |
for (i = 0; i < bytes.length; i++) { | |
var byteVal = bytes.charCodeAt(i); | |
if (byteVal < 32 || byteVal > 127) { | |
readable += "\\x" + ("0" + byteVal.toString(16).toUpperCase()).slice(-2); | |
} else { | |
readable += bytes[i]; | |
} | |
} | |
return readable; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment