I have an Ascii value (something like "@") that I want to convert into an hex in JavaSkript that I can compare this value with some other hex-values. Are there any casting possiblities?
Best regards and thanks,
Florian
I have an Ascii value (something like "@") that I want to convert into an hex in JavaSkript that I can compare this value with some other hex-values. Are there any casting possiblities?
Best regards and thanks,
Florian
Convert Ascii strings into base64 (hex)
var b64 = btoa("@#%#@!@#$%");
Convert base64 to Ascii:
atob(b64);
Don't know what you want to compare, beside equality.
// Convert a (UTF-8 or ASCII) string to HEX:
function stringToHex(string) {
return '0x'+[...string].map(char => char.codePointAt(0).toString(16)).join('')
}
// Convert a HEX string into a number:
function hexToNumber(hex) {
return parseInt(hex, 16)
}