Advertisement
NyteOwlDave

Convert string to hex character codes

Mar 13th, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // Takes in a 12 character string and converts
  3. // input each character to an equivalent hex code.
  4. // Concatenates the hex codes into a single string
  5. // and returns that.
  6. const toHex = (str) => {
  7.     var result = '';
  8.     for (var i=0;i<str.length;i++){
  9.         result += str.charCodeAt(i).toString(16);
  10.     }
  11.     return result;
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement