Try it

Characters (· = space, ↵ = newline)

Hi·there!

Hex bytes

486920746865726521
Hex bytes48 69 20 74 68 65 72 65 21

Understand the result

What's going on

A computer never stores the letter “A” - it stores the number 65. ASCII is just an agreed-upon table that maps every character you can type to a number, and hex is the compact way engineers usually write that number down.

The formula

hex = ASCII_code(char).toString(16)

Repeated for every character in the string, left to right.

Show the derivation, mnemonic, and worked example

Build it up

Take a string, and look up each character’s position in the ASCII table one at a time. That position is a plain decimal number between 0 and 255, which converts to exactly two hex digits. String those hex pairs together, usually with a space between characters, and you’ve got the raw bytes a program or a serial monitor would actually see.

Worked example

Worked example

Text: "Hi"

'H' = 72 decimal = 48 hex

'i' = 105 decimal = 69 hex

Result: 48 69