Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created September 15, 2014 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shigemk2/add259a622ff88c998eb to your computer and use it in GitHub Desktop.
Save shigemk2/add259a622ff88c998eb to your computer and use it in GitHub Desktop.
/**
* 文字列を16進数に変換する
* 16進数ひとけたの場合は01 02 03と表記する
*
* @method hex
* @param {String} s 文字列
* @return {String} result 16進数に変換した文字列
*/
function hex(s) {
var result="";
for(var i=0;i<s.length;++i){
var h = ("0"+s.charCodeAt(i).toString(16)).substr(-2);
result += h;
}
return result;
}
console.log("abc");
console.log(hex("abc")); // 616263
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment