Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert ASCII number to ASCII Character in C

Tags:

c

types

ascii

In C is there a way to convert an ASCII value typed as an int into the the corresponding ASCII character as a char?

like image 773
Anonymous Avatar asked Jul 12 '11 06:07

Anonymous


People also ask

How do you convert a numerical value to an ASCII character?

You can use one of these methods to convert number to an ASCII / Unicode / UTF-16 character: You can use these methods convert the value of the specified 32-bit signed integer to its Unicode character: char c = (char)65; char c = Convert. ToChar(65);

How do you convert between ASCII and char?

You must first convert the character to its ASCII value. In LiveCode, this is done with the charToNum function. Converting a number to the corresponding character is done with the numToChar function. The first of these statements converts a number to a character; the second converts a character to its ASCII value.

What is the ASCII value of A to Z?

Below are the implementation of both methods: Using ASCII values: ASCII value of uppercase alphabets – 65 to 90. ASCII value of lowercase alphabets – 97 to 122.

What is the ASCII value of 0 to 9?

It can be observed that ASCII value of digits [0 – 9] ranges from [48 – 57]. Therefore, in order to print the ASCII value of any digit, 48 is required to be added to the digit. Below is the implementation of the above approach: C++


1 Answers

You can assign int to char directly.

int a = 65;
char c = a;
printf("%c", c);

In fact this will also work.

printf("%c", a);  // assuming a is in valid range
like image 195
taskinoor Avatar answered Oct 20 '22 11:10

taskinoor