String.prototype.hexEncode=function(){ var r=''; var i=0; var h; while(i<this.length){ h=this.charCodeAt(i++).toString(16); while(h.length<2){ h=h; } r+=h; } return r; }; String.prototype.hexDecode=function(){ var r=''; for(var i=0; i<this.length; i+=2){ r+=unescape('%'+this.substr(i,2)); } return r; };
- Example:
- 'Tya Ganteng :P'.hexEncode()
- will return:
- 5479612047616e74656e67203a50
- and
- '5479612047616e74656e67203a50'.hexDecode()
- will return:
- Tya Ganteng :P
Haha.. :D
0 komentar:
Posting Komentar