The C ASCII character set: character, decimal, hexadecimal and octal conversions C program example

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)

Other info: none

To do: Doing the C character, decimal, hexadecimal and octal conversion in C programming

To show: The C ASCII character set: character, decimal, hex and octal conversions C program example

 

#include <stdio.h>

 

int main(void)

{

int num;

 

printf("Conversion...\n");

printf("Start with any character and ");

printf("press Enter/Carriage return, EOF to stop\n");

num = getchar();

printf("Character Integer Hexadecimal Octal\n");

 

while(getchar() != EOF)

{

printf(" %c %d %x %o\n", num, num, num, num);

++num;

}

return 0;

}

 

Output example:

 

Conversion...

Start with any character and press Enter/Carriage return, EOF to stop

A

Character Integer Hexadecimal Octal

A                 65             41             101

B                 66             42             102

C                 67             43             103

D                 68             44             104

E                 69             45             105

F                 70             46             106

G                 71             47             107

H                 72             48             110

I                   73             49             111

J                 74              4a             112

K                75              4b             113

L                 76              4c             114

M                77              4d             115

N                 78             4e              116

O                 79             4f               117

Press any key to continue . . .

 

 

You can compare to the ASCII table at: The ASCII Table.

 

 

C and C++ Programming Resources | C & C++ Code Example Index