I'm looking for a way to uniformly convert JavaScript chars to binary. One problem that I'm facing is that I'm not able to convert strings used in unescape function correctly
document.write("HI"); ==> HI (case 1)
document.write("\x48\x49"); ==> HI (case 2)
document.write(unescape("%48%49")); ==> HI (case 3)
Case 1: Converting "HI" to binary generates:
0100100001001001
Case 2: Converting "\x48\x49" to binary generates:
0100100001001001
Case 3: Converting "%48%49" to binary generates:
001001010011010000111000001001010011010000111001
I understand what is happening in case 3. it converts each char to binary without realizing that these chars are in hex representation. How can I make case 3 have the same binary representation as case 1 and case 2 without any pre-processing required?