Skip to content

How to Convert ASCII to Hexadecimal

Published: at 05:30 AM

Converting ASCII to hexadecimal is a common task in computer programming. ASCII is a character encoding standard that assigns a unique number to each character. Hexadecimal, on the other hand, is a base-16 number system that uses sixteen digits, 0 through 9 and A through F. Converting ASCII to hexadecimal involves converting each character to its corresponding hexadecimal value.

Conversion

Here’s a step-by-step guide on how to convert ASCII to hexadecimal:

  1. Choose the ASCII character you want to convert to hexadecimal.
  2. Convert the ASCII character to its decimal value using an ASCII table.
  3. Convert the decimal value to hexadecimal using the division-by-16 method.
  4. Pad the hexadecimal value with leading zeros to make it 2 digits long (if necessary).

Example

Let’s walk through an example to illustrate the process. Suppose we want to convert the ASCII character ‘A’ to hexadecimal.

  1. The ASCII value of ‘A’ is 65.

  2. To convert 65 to hexadecimal, we use the division-by-16 method. We divide 65 by 16 and get a quotient of 4 with a remainder of 1. We write down the remainder (1) as the least significant digit of the hexadecimal value. We then divide 4 by 16 and get a quotient of 0 with a remainder of 4. We write down the remainder (4) as the next digit of the hexadecimal value. The hexadecimal value of 65 is 41.

    QuotientRemainderHexadecimal
    65/16=465/16=411
    4/16=04/16=0441
  3. Since the hexadecimal value we obtained in step 2 is only 2 digits long, we don’t need to pad it with leading zeros.

ASCII-Hexadecimal Table

Here’s a table of the ASCII characters and their corresponding hexadecimal values:

CharacterDescriptionDecimalHexadecimal
0Zero4830
1One4931
2Two5032
3Three5133
4Four5234
5Five5335
6Six5436
7Seven5537
8Eight5638
9Nine5739
ACapital A6541
BCapital B6642
CCapital C6743
DCapital D6844
ECapital E6945
FCapital F7046
GCapital G7147
HCapital H7248
ICapital I7349
JCapital J744A
KCapital K754B
LCapital L764C
MCapital M774D
NCapital N784E
OCapital O794F
PCapital P8050
QCapital Q8151
RCapital R8252
SCapital S8353
TCapital T8454
UCapital U8555
VCapital V8656
WCapital W8757
XCapital X8858
YCapital Y8959
ZCapital Z905A
aSmall a9761
bSmall b9862
cSmall c9963
dSmall d10064
eSmall e10165
fSmall f10266
gSmall g10367
hSmall h10468
iSmall i10569
jSmall j1066A
kSmall k1076B
lSmall l1086C
mSmall m1096D
nSmall n1106E
oSmall o1116F
pSmall p11270
qSmall q11371
rSmall r11472
sSmall s11573
tSmall t11674
uSmall u11775
vSmall v11876
wSmall w11977
xSmall x12078
ySmall y12179
zSmall z1227A

See full ascii table here.

References