Skip to content

Instantly share code, notes, and snippets.

@designstorming
Created February 21, 2019 15:27
Show Gist options
  • Save designstorming/c0ad0b6b834e46c48ec870adb189fb19 to your computer and use it in GitHub Desktop.
Save designstorming/c0ad0b6b834e46c48ec870adb189fb19 to your computer and use it in GitHub Desktop.
Convert string to hex array
/**
* This will convert string to hex array
*
* Steps:
* 1. Split string into letter array
* 2. Iterate over every item
* 3. Convert item to decimal code
* 4. Convert result to hex string
* 5. Lastly, parse integer to hex
*/
let result = Array
.from('Test string')
.reduce((accumulator, char, index) => {
accumulator.push(parseInt(c.charCodeAt(0).toString(16)));
return accumulator;
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment