Browse - Programming Tips - JavaScript: String to/from hex

Date: 2019sep13
Language: javaScript

Q.  JavaScript: String to/from hex

A.  Straight ahead functions that work

function strToHex(str) { var out = ''; for (var i = 0; i < str.length; i++ ) { out += zeroPad(str.charCodeAt(i).toString(16), 2); } return out; }
function hexToStr(hex) { var str = ''; for (var i = 0; i < hex.length; i += 2) { str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); } return str; }
http://davekb.com/search.php?target=zeroPad