-
-
Save myfreeer/055d00ea02395482aa1405bd82d246e7 to your computer and use it in GitHub Desktop.
Convert bytes to string Javascript
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 str2arr(str){ | |
var array_=new Array(); | |
for(var i = 0; i < str.length; ++i){ | |
array_[i]=str.charCodeAt(i);}; | |
return array_; | |
} | |
function hex2arr(str){ | |
var b_=new Uint8Array(); | |
eval("b_=["+str+"]"); | |
return b_; | |
} | |
function bin2string(array){ | |
var result = ""; | |
for(var i = 0; i < array.length; ++i){ | |
result+= (String.fromCharCode(array[i])); | |
} | |
return result; | |
} | |
function hex2string(str){ | |
return eval('String.fromCharCode('+str+')'); | |
} | |
var hexstr="0x23,0x66,0x78,0x85,0xff,0x00" | |
bin2string(hex2arr(hexstr)); | |
hex2string(hexstr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment