Created
September 15, 2014 08:08
-
-
Save shigemk2/add259a622ff88c998eb to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* 文字列を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