Here is how to convert ASCII text to hex: find the ASCII value of each character, write that value as two hexadecimal digits, and keep the characters in their original order. For example, ID=42 becomes 49 44 3D 34 32.

That small conversion is useful when a device expects a command as bytes, an API requires a hex-encoded field, or you need to inspect invisible characters in a message. A reliable result preserves everything in the source, including spaces, letter case, punctuation, and line endings.

The method you choose depends on the task. Manual lookup works for a short example. A converter handles occasional text, while code is better for repeatable output and strict input checks. Before using any method, confirm that your source really is ASCII and that the receiving system expects the format you plan to produce. The complete ASCII chart below provides the character codes needed for manual lookup.

The Conversion in Four Actions

To convert ASCII to hexadecimal, read each character, look up its numeric ASCII code, convert that code to base 16, and write it with two digits. Join the results in order. ASCII values range from decimal 0 to 127, so every encoded byte falls between hex 00 and 7F.

Check the Input Before Choosing a Tool

ASCII, short for American Standard Code for Information Interchange, defines 128 character codes. These include English letters, decimal digit characters, common punctuation, and control characters such as tabs and line feeds.

ASCII character codes identify the source characters; hexadecimal notation changes how their numeric values are displayed.

The printable ASCII range runs from 20 through 7E in hexadecimal, including space. Values below 20, along with 7F, cover non-printing codes. A message can therefore be valid ASCII even when some of its contents are invisible.

Plain "status" uses ASCII characters. Curly quotation marks around that same word do not. Accented names, emojis, and many currency symbols also require another character encoding.

Avoid treating “extended ASCII” as one universal format. Different eight-bit encodings assign different meanings to values above 127. If an application requires strict ASCII, rejecting unsupported input is safer than silently deleting or replacing it.

For ASCII-only text, UTF-8 produces the same byte values. That compatibility is useful, but a tool that accepts all Unicode text is doing more than strict ASCII encoding. Its label alone does not establish what happens outside the ASCII range.

Hands typing on a computer keyboard beside a softly blurred screen.
Test a known example before converting a larger input. Original AI-generated editorial photograph.

ASCII Table: All 128 Character Codes in Decimal, Hex, and Binary

Use this ASCII code table to find a character's decimal code, two-digit hexadecimal code, and binary representation. Standard ASCII is a seven-bit character set with values 0–127. The ASCII binary values below use an eight-bit byte display, so the first bit is always zero.

For manual conversion, locate the source character and copy its hex value. To convert ID=42, for instance, use the rows for I, D, =, 4, and 2, then keep those values in the same order. The decimal column lets you check an ASCII decimal-to-hex calculation without confusing the character with the number it spells.

ASCII Control Characters: Decimal 0–31

These are non-printing codes, so the symbol column shows a standard abbreviation and its meaning. They still occupy bytes when present in the input. HT, LF, and CR are especially useful when checking tabs and line endings.

Decimal Code

Hex Code

Binary (8-bit display)

Symbol / Meaning

0

00

00000000

NUL: Null

1

01

00000001

SOH: Start of heading

2

02

00000010

STX: Start of text

3

03

00000011

ETX: End of text

4

04

00000100

EOT: End of transmission

5

05

00000101

ENQ: Enquiry

6

06

00000110

ACK: Acknowledge

7

07

00000111

BEL: Bell

8

08

00001000

BS: Backspace

9

09

00001001

HT: Horizontal tab

10

0A

00001010

LF: Line feed

11

0B

00001011

VT: Vertical tab

12

0C

00001100

FF: Form feed

13

0D

00001101

CR: Carriage return

14

0E

00001110

SO: Shift out

15

0F

00001111

SI: Shift in

16

10

00010000

DLE: Data link escape

17

11

00010001

DC1: Device control 1

18

12

00010010

DC2: Device control 2

19

13

00010011

DC3: Device control 3

20

14

00010100

DC4: Device control 4

21

15

00010101

NAK: Negative acknowledge

22

16

00010110

SYN: Synchronous idle

23

17

00010111

ETB: End of transmission block

24

18

00011000

CAN: Cancel

25

19

00011001

EM: End of medium

26

1A

00011010

SUB: Substitute

27

1B

00011011

ESC: Escape

28

1C

00011100

FS: File separator

29

1D

00011101

GS: Group separator

30

1E

00011110

RS: Record separator

31

1F

00011111

US: Unit separator

ASCII Printable Characters: Decimal 32–126

This ASCII to hex table covers space, punctuation, digits, uppercase letters, and lowercase letters. Space is labeled explicitly because an empty cell would hide it. The remaining symbols are the actual ASCII printable characters, with letter case preserved.

Decimal Code

Hex Code

Binary (8-bit display)

Character

32

20

00100000

SPACE

33

21

00100001

!

34

22

00100010

"

35

23

00100011

#

36

24

00100100

$

37

25

00100101

%

38

26

00100110

&

39

27

00100111

'

40

28

00101000

(

41

29

00101001

)

42

2A

00101010

*

43

2B

00101011

+

44

2C

00101100

,

45

2D

00101101

-

46

2E

00101110

.

47

2F

00101111

/

48

30

00110000

0

49

31

00110001

1

50

32

00110010

2

51

33

00110011

3

52

34

00110100

4

53

35

00110101

5

54

36

00110110

6

55

37

00110111

7

56

38

00111000

8

57

39

00111001

9

58

3A

00111010

:

59

3B

00111011

;

60

3C

00111100

<

61

3D

00111101

=

62

3E

00111110

>

63

3F

00111111

?

64

40

01000000

@

65

41

01000001

A

66

42

01000010

B

67

43

01000011

C

68

44

01000100

D

69

45

01000101

E

70

46

01000110

F

71

47

01000111

G

72

48

01001000

H

73

49

01001001

I

74

4A

01001010

J

75

4B

01001011

K

76

4C

01001100

L

77

4D

01001101

M

78

4E

01001110

N

79

4F

01001111

O

80

50

01010000

P

81

51

01010001

Q

82

52

01010010

R

83

53

01010011

S

84

54

01010100

T

85

55

01010101

U

86

56

01010110

V

87

57

01010111

W

88

58

01011000

X

89

59

01011001

Y

90

5A

01011010

Z

91

5B

01011011

[

92

5C

01011100

\

93

5D

01011101

]

94

5E

01011110

^

95

5F

01011111

_

96

60

01100000

`

97

61

01100001

a

98

62

01100010

b

99

63

01100011

c

100

64

01100100

d

101

65

01100101

e

102

66

01100110

f

103

67

01100111

g

104

68

01101000

h

105

69

01101001

i

106

6A

01101010

j

107

6B

01101011

k

108

6C

01101100

l

109

6D

01101101

m

110

6E

01101110

n

111

6F

01101111

o

112

70

01110000

p

113

71

01110001

q

114

72

01110010

r

115

73

01110011

s

116

74

01110100

t

117

75

01110101

u

118

76

01110110

v

119

77

01110111

w

120

78

01111000

x

121

79

01111001

y

122

7A

01111010

z

123

7B

01111011

{

124

7C

01111100

|

125

7D

01111101

}

126

7E

01111110

~

The Final Standard ASCII Code: DEL

Decimal Code

Hex Code

Binary (8-bit display)

Symbol / Meaning

127

7F

01111111

DEL: Delete

The ASCII hex values for decimal digits run from 30 to 39; uppercase letters use 41–5A, and lowercase letters use 61–7A. Values 128–255 are not part of this standard ASCII table. If a tool offers an extended table, check which eight-bit encoding it uses before applying those additional mappings.

How to Convert ASCII Text to Hex by Hand

Use the source string ID=42. It contains five characters, with no spaces or line break.

Source Character

ASCII Decimal

Hexadecimal Byte

I

73

49

D

68

44

=

61

3D

4

52

34

2

50

32

Read down the last column to get 49 44 3D 34 32. Without display separators, the output is 49443D3432.

If you have decimal ASCII values rather than a hex table, divide each value by 16. The quotient gives the first digit and the remainder gives the second. Remainders ten through fifteen become A–F.

For the equals sign:

61 ÷ 16 = 3 remainder 13 → 3D

Keep two digits for every byte. A tab has decimal code 9, so its hex representation is 09, not a lone 9 in a byte-oriented output.

Do not convert the number 42 as one integer in this example. The source contains the text characters 4 and 2, which become 34 32. Decimal integer 42 would instead be hexadecimal 2A. The input's type determines the operation.

Grid-paper notebook, pencil, keyboard and USB cable on a desk.
Work through a small example and verify the result. Original AI-generated editorial photograph.

Use an Online Converter Without Changing the Message

An ASCII text to hex converter can save time, especially when the message includes several punctuation marks or repeated spaces. The useful settings are the input encoding, output delimiter, prefix, and letter case.

  1. Paste the exact source text into the input field.
  2. Select ASCII if the tool offers a strict encoding choice.
  3. Choose continuous output or a separator the destination accepts.
  4. Check any prefix setting, such as 0x per byte.
  5. Convert, then compare the result with a known example.

Use ID=42 as a quick check: the bytes should be 49 44 3D 34 32. If the result includes another 20, the input may have a space. An ending 0A suggests a line feed.

Choose the conversion direction explicitly when the tool has automatic detection. The text FACE consists entirely of valid hexadecimal digits, so an auto-detect feature might decode it instead of encoding its four ASCII characters. Text mode should produce 46 41 43 45.

For private input, review the tool's processing and retention information. Do not assume that a converter runs locally just because it appears in a browser.

Python ASCII to Hex with Strict Input Checking

Python provides a direct way to reject non-ASCII characters before creating hexadecimal bytes:

message = "ID=42"
data = message.encode("ascii", errors="strict")
print(data.hex())             # 49443d3432
print(data.hex(" ").upper())  # 49 44 3D 34 32

The first operation creates the encoded bytes. The .hex() method then displays those bytes in base 16. Uppercasing changes the presentation of hex letters without changing the represented data.

To produce a byte array initializer:

print(", ".join(f"0x{byte:02X}" for byte in data))
# 0x49, 0x44, 0x3D, 0x34, 0x32

The 02X format keeps each byte two digits wide. That matters for low-valued control codes.

If the source includes a non-ASCII character, .encode("ascii") raises UnicodeEncodeError. Preserve that failure when the receiving system requires ASCII. Using errors="ignore" removes unsupported characters; errors="replace" substitutes them. Either option changes the original message.

For a text file whose contents must already be ASCII, inspect the bytes without normalizing line endings:

from pathlib import Path
raw = Path("request.txt").read_bytes()
raw.decode("ascii")  # Validate; raises an error for non-ASCII bytes.
print(raw.hex())

Reading bytes also preserves an existing final newline. Validate and inspect it rather than stripping it automatically.

JavaScript ASCII to Hex in Browsers and Node.js

A reusable conversion function should validate the ASCII limit before formatting each code. For ASCII input, JavaScript's UTF-16 code units match the required character values.

function asciiToHex(text, separator = " ") {
  const pairs = [];
  for (let index = 0; index < text.length; index++) {
    const value = text.charCodeAt(index);
    if (value > 0x7f) {
      throw new Error(`Non-ASCII character at index ${index}`);
    }
    pairs.push(value.toString(16).padStart(2, "0").toUpperCase());
  }
  return pairs.join(separator);
}
console.log(asciiToHex("ID=42"));
// 49 44 3D 34 32
console.log(asciiToHex("ID=42", ""));
// 49443D3432

The validation makes this a strict ASCII operation. Removing it would allow larger UTF-16 code-unit values, which are not a general substitute for encoded Unicode bytes.

In Node.js, validate first and use a Buffer for the conversion:

function asciiToHexNode(text) {
  if (/[^\x00-\x7f]/.test(text)) {
    throw new Error("Expected ASCII-only input");
  }
  return Buffer.from(text, "utf8").toString("hex");
}
console.log(asciiToHexNode("ID=42")); // 49443d3432

UTF-8 produces the correct bytes here because validation has limited the input to ASCII. Do not rely on Node's 'ascii' encoding name to provide strict rejection: its legacy behavior differs from Python's strict ASCII encoder.

Generate Plain Hex from a Shell or File

On systems with xxd installed, this command converts a short literal without appending a newline to the input:

printf '%s' 'ID=42' | xxd -p

The output is 49443d3432. The newline that terminates the displayed result is not an extra encoded byte in the message.

Use a fixed printf format such as %s and pass the text separately. This prevents percent signs in the source from being interpreted as formatting instructions. A shell variable can be supplied as printf '%s' "$message".

If xxd is unavailable, a system with od can show the same bytes:

printf '%s' 'ID=42' | od -An -v -tx1

This produces space-separated values 49 44 3d 34 32, with possible layout whitespace. The options suppress the address column, show repeated data, and select one-byte hexadecimal output.

For an existing file:

xxd -p request.txt

This displays the file's existing bytes. It does not verify that those bytes belong to ASCII. For strict ASCII validation, use the Python file example before accepting the output.

The -p option selects plain hex rather than a dump with address offsets and a readable sidebar. Long output may be line-wrapped; whether to remove those display breaks depends on the destination. Preserve actual newline bytes that are part of the source message.

Pick the Hex Output Format Your Destination Expects

String to hexadecimal conversion does not have one universal display layout. The same five bytes can appear in several forms:

Output Style

Example for ID=42

Typical Purpose

Continuous

49443D3432

A field requiring uninterrupted hex

Space-separated

49 44 3D 34 32

Human inspection

Comma-separated constants

0x49, 0x44, 0x3D, 0x34, 0x32

Code initializer elements

Backslash escapes

\x49\x44\x3D\x34\x32

A compatible escaped literal

Prefixes, commas, and backslashes are notation. A receiver that expects raw hexadecimal digits may reject them, even though they describe the correct values elsewhere.

For n ASCII characters, including any control characters, the encoded message contains n bytes. Continuous hex therefore has 2 × n digits, excluding prefixes and separators. Five characters give ten digits.

Also check whether the destination expects hex text or raw bytes. These are different payloads. For the source OK, the original ASCII bytes are 4F 4B. Their continuous hex representation is the four-character string 4F4B.

If you send that representation as ordinary ASCII text, the transmitted bytes are 34 46 34 42, which spell the four digits and letters. If you parse the hex and send the resulting bytes, the transmitted data is the original two-byte message. A serial terminal or API may offer separate “text” and “hex” input modes, so choose the mode that matches its documentation.

Do not add a null terminator unless the interface requires one. Some programming environments use a zero byte to mark the end of a string, but that convention does not make 00 part of every ASCII message. An extra terminator changes the payload length and may affect how the receiver processes it.

An actual space in the source contributes byte 20. A space inserted between displayed byte pairs only helps readability. Keep those two roles separate when checking output length.

Verify the Result and Diagnose Extra Bytes

A round-trip check converts the hex back into bytes and decodes them using ASCII:

hex_output = "49443D3432"
recovered = bytes.fromhex(hex_output).decode("ascii")

assert recovered == "ID=42"

That confirms the complete message, including case and punctuation, survived. For longer data, compare byte counts as well as the recovered text.

Line endings deserve special attention when preparing commands. The five visible letters and symbols are not always the whole message. For example, PING followed by carriage return and newline becomes:

50 49 4E 47 0D 0A

The printable word uses four bytes; the two control characters bring the total to six. A device expecting that ending may reject a message containing only 0A or no ending at all.

Inspect the original source when every conversion method produces the same unexpected bytes. A UTF-8 file saved with a byte order mark begins with EF BB BF, which is outside ASCII. A strict ASCII check should reject those bytes rather than hide them. Confirm the file's required encoding before removing a marker or resaving it.

Other clues include 09 for a tab, 00 for a null byte, and an unexpected final 20 for a trailing space. A tool may display control bytes as dots or escapes rather than visible characters.

Avoid “fixing” output by deleting unfamiliar pairs. First compare them with the input and the protocol's requirements. A missing control character can be just as harmful as an unwanted one.

Copper traces and a memory chip on a printed circuit board.
Keep the byte representation and its interpretation together. Original AI-generated editorial photograph.

Practical Questions About ASCII-to-Hex Conversion

Does conversion preserve spaces and tabs?

Yes, when the encoder processes the source unchanged. A space becomes 20, and a tab becomes 09. These bytes belong to the message, unlike separators added between hex pairs for readability. Check whether the tool trims input or whether an earlier copy-and-paste step changed tabs into spaces before encoding.

Can I convert emojis or accented characters as ASCII?

Strict ASCII cannot represent them. Choose an encoding supported by the destination, commonly UTF-8, or revise the source to valid ASCII if the protocol requires it. That is an explicit input decision. Do not silently discard unsupported characters and assume the resulting hex still describes the original message.

How do I convert decimal ASCII codes into hex?

Treat each decimal code as a separate character value between 0 and 127, then format it as a two-digit hexadecimal number. The list 79, 75 becomes 4F 4B, representing OK. Encoding the literal text 79, 75 instead would also encode the digits, comma, and space, producing a different result.

Why does my result end with 0A?

Hex 0A is a line feed. It often appears because the input has a final newline or a command generated one before conversion. Inspect the original file or string rather than assuming the converter added it. Some commands require that byte, so remove it only when the receiving format excludes it.

Why do two ASCII-to-hex tools return different results?

Compare the input, encoding, delimiters, prefixes, and letter case. Different display styles can describe identical bytes. Differences in the byte values can indicate trimmed whitespace, altered line endings, or non-ASCII input handled differently. Start with a small known string, then compare the actual pairs rather than the overall visual layout.

Can I turn the hex output back into ASCII?

Yes. Parse complete hex pairs into bytes and decode those bytes using ASCII. A strict decoder rejects byte values above 7F, even if they form valid hexadecimal pairs. If the original message used another encoding, use that same encoding for decoding. Hex to ASCII is reversible when the input and encoding remain intact.

Does ASCII-to-hex conversion make the output smaller?

No. Each source byte becomes two hexadecimal digits. If you store those digits as ASCII or UTF-8 text, continuous hex uses twice the original byte count, before any separators. It helps people inspect and exchange byte values; it is not compression, encryption, or a way to hide readable content securely.

Preserve the Message Before Formatting It

Knowing how to convert ASCII text to hex is most useful when you also verify what was encoded. Reject unsupported characters, preserve meaningful whitespace, and match the receiving format. Then decode the result once to confirm that the text and byte count agree with the original message.