I need to communicate between Javascript and PHP (I use jQuery for AJAX), but the output of the PHP script may contain binary data. That\'s why I use bin2hex()
function hex2bin(hex)
{
var bytes = [], str;
for(var i=0; i< hex.length-1; i+=2)
bytes.push(parseInt(hex.substr(i, 2), 16));
return String.fromCharCode.apply(String, bytes);
}
thanks to Andris!
Other useful information about this topic (dex2bin,bin2dec) can be found here.
According to that, here is a bin2hex solution:
parseInt(1100,2).toString(16); //--> c