140k views
3 votes
How to convert ascii to hexadecimal?

User Pablopixel
by
6.3k points

1 Answer

5 votes
ASCII is an agreement on which number represents which typographic character. Using this table you can look up the number of any character. For instance, "A" has 65, but that is a decimal. Next step is to represent this decimal number in hexadecimal. You can do that by taking the divisor and remainder of a division by 16. Numbers beyond 9 are represented as a through f. Hexadecimal numbers are commonly prefixed by "0x" to make them recognizable.

So "A" = 65 = 4*16+1 = 0x41

And "Z" = 90 = 5*16+10 = 0x5a

There are ASCII tables that have the hexadecimal value in them, to make the task easier (www.asciitable.com).

If you want to do this programmatically, you can write something like this (node.js):

console.log( Buffer.from('AZ', 'utf8').toString('hex'));

Note that the 0x prefix is not shown here.
User Blackholyman
by
5.5k points