Advertisement
NyteOwlDave

Convert string to hex character codes #2

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