Created
February 21, 2019 15:27
-
-
Save designstorming/c0ad0b6b834e46c48ec870adb189fb19 to your computer and use it in GitHub Desktop.
Convert string to hex array
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
/** | |
* 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