0

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

3

2 Answers 2

0

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.

1
0
// 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)
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.