How to Convert ASCII to Octal

Author

CODINASION

Published on Jan 26, 2022

Converting ASCII to octal is a common task in computer programming. ASCII is a character encoding standard that assigns a unique number to each character. Octal, on the other hand, is a base-8 number system that uses eight digits, 0 through 7. Converting ASCII to octal involves converting each character to its corresponding octal value.

Conversion

Here's a step-by-step guide on how to convert ASCII to octal:

  1. Choose the ASCII character you want to convert to octal.
  2. Convert the ASCII character to its decimal value using an ASCII table.
  3. Convert the decimal value to octal using the division-by-8 method.
  4. Pad the octal value with leading zeros to make it 3 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 octal.

  1. The ASCII value of 'A' is 65.

  2. To convert 65 to octal, we use the division-by-8 method. We divide 65 by 8 and get a quotient of 8 with a remainder of 1. We write down the remainder (1) as the least significant digit of the octal value. We then divide 8 by 8 and get a quotient of 1 with a remainder of 0. We write down the remainder (0) as the next digit of the octal value. We continue this process until we have 3 digits. The octal value of 65 is 101.

    QuotientRemainderOctal
    65/8=865/8=811
    8/8=18/8=1001
    1/8=01/8=01101
  3. Since the octal value we obtained in step 2 is only 3 digits long, we don't need to pad it with leading zeros.

ASCII-Octal Table

Here's a table that shows the ASCII values of all characters and their corresponding octal values:

CharacterDescriptionDecimalOctal
0Zero4860
1One4961
2Two5062
3Three5163
4Four5264
5Five5365
6Six5466
7Seven5567
8Eight5670
9Nine5771
ACapital A65101
BCapital B66102
CCapital C67103
DCapital D68104
ECapital E69105
FCapital F70106
GCapital G71107
HCapital H72110
ICapital I73111
JCapital J74112
KCapital K75113
LCapital L76114
MCapital M77115
NCapital N78116
OCapital O79117
PCapital P80120
QCapital Q81121
RCapital R82122
SCapital S83123
TCapital T84124
UCapital U85125
VCapital V86126
WCapital W87127
XCapital X88130
YCapital Y89131
ZCapital Z90132
aSmall a97141
bSmall b98142
cSmall c99143
dSmall d100144
eSmall e101145
fSmall f102146
gSmall g103147
hSmall h104150
iSmall i105151
jSmall j106152
kSmall k107153
lSmall l108154
mSmall m109155
nSmall n110156
oSmall o111157
pSmall p112160
qSmall q113161
rSmall r114162
sSmall s115163
tSmall t116164
uSmall u117165
vSmall v118166
wSmall w119167
xSmall x120170
ySmall y121171
zSmall z122172

See full ascii table here.

References

Heart with ribbonBecome a SponsorHeart with ribbon

Become a sponsor and help us maintain and improve this project. Every contribution counts. Thank you!