Comment trouver la valeur ASCII d'un caractère ?

Comment trouver la valeur ASCII d'un caractère ?

'ASCII' signifie 'American Standard Code for Information Interchange'. Les codes ASCII représentent du texte dans les ordinateurs, les équipements de télécommunications et d'autres appareils. L'ASCII convertit les informations en formats numériques standardisés qui permettent aux ordinateurs de traiter des données, de stocker des données et de communiquer efficacement avec d'autres ordinateurs.





Dans cet article, vous apprendrez à trouver la valeur ASCII d'un caractère en utilisant C++, Python, JavaScript et C.





skype affichant des messages dans le désordre

Énoncé du problème

On vous donne un caractère et vous devez imprimer la valeur ASCII de ce caractère.





Exemple 1 : Soit le caractère donné 'M'.

La valeur ASCII de 'M' est 77.



Ainsi, la sortie est 77.

Exemple 2 : Soit le caractère donné 'U'.





La valeur ASCII de 'U' est 85.

Ainsi, la sortie est de 85.





Exemple 3 : Soit le caractère donné 'O'.

La valeur ASCII de 'O' est 79.

Ainsi, la sortie est de 79.

Si vous souhaitez consulter le tableau ASCII complet, vous pouvez consulter site web d'asciitable .

En rapport: Quelle est la différence entre le texte ASCII et Unicode ?

Programme C++ pour trouver la valeur ASCII d'un caractère

Vous pouvez trouver la valeur ASCII d'un caractère en utilisant entier() en C++. Ci-dessous se trouve le programme C++ pour imprimer la valeur ASCII d'un caractère :

comment faire une antenne de télévision numérique
// C++ program to find the ASCII value of a character
#include
using namespace std;
int main()
{
char ch1 = 'M';
char ch2 = 'U';
char ch3 = 'O';
char ch4 = 'm';
char ch5 = 'a';
char ch6 = 'k';
char ch7 = 'e';
char ch8 = 'u';
char ch9 = 's';
char ch10 = 'e';
char ch11 = 'o';
char ch12 = 'f';
// int() is used to convert character to its ASCII value
cout << 'ASCII value of ' << ch1 << ' is ' << int(ch1) << endl;
cout << 'ASCII value of ' << ch2 << ' is ' << int(ch2) << endl;
cout << 'ASCII value of ' << ch3 << ' is ' << int(ch3) << endl;
cout << 'ASCII value of ' << ch4 << ' is ' << int(ch4) << endl;
cout << 'ASCII value of ' << ch5 << ' is ' << int(ch5) << endl;
cout << 'ASCII value of ' << ch6 << ' is ' << int(ch6) << endl;
cout << 'ASCII value of ' << ch7 << ' is ' << int(ch7) << endl;
cout << 'ASCII value of ' << ch8 << ' is ' << int(ch8) << endl;
cout << 'ASCII value of ' << ch9 << ' is ' << int(ch9) << endl;
cout << 'ASCII value of ' << ch10 << ' is ' << int(ch10) << endl;
cout << 'ASCII value of ' << ch11 << ' is ' << int(ch11) << endl;
cout << 'ASCII value of ' << ch12 << ' is ' << int(ch12) << endl;

return 0;
}

Sortir:

ASCII value of M is 77
ASCII value of U is 85
ASCII value of O is 79
ASCII value of m is 109
ASCII value of a is 97
ASCII value of k is 107
ASCII value of e is 101
ASCII value of u is 117
ASCII value of s is 115
ASCII value of e is 101
ASCII value of o is 111
ASCII value of f is 102

En rapport: Qu'est-ce que le texte ASCII et comment est-il utilisé ?

Programme Python pour trouver la valeur ASCII d'un caractère

Vous pouvez trouver la valeur ASCII d'un caractère en utilisant mots() en Python. Ci-dessous se trouve le programme Python pour imprimer la valeur ASCII d'un caractère :

# Python program to find the ASCII value of a character
ch1 = 'M'
ch2 = 'U'
ch3 = 'O'
ch4 = 'm'
ch5 = 'a'
ch6 = 'k'
ch7 = 'e'
ch8 = 'u'
ch9 = 's'
ch10 = 'e'
ch11 = 'o'
ch12 = 'f'
# ord() is used to convert character to its ASCII value
print('ASCII value of', ch1, 'is', ord(ch1))
print('ASCII value of', ch2, 'is', ord(ch2))
print('ASCII value of', ch3, 'is', ord(ch3))
print('ASCII value of', ch4, 'is', ord(ch4))
print('ASCII value of', ch5, 'is', ord(ch5))
print('ASCII value of', ch6, 'is', ord(ch6))
print('ASCII value of', ch7, 'is', ord(ch7))
print('ASCII value of', ch8, 'is', ord(ch8))
print('ASCII value of', ch9, 'is', ord(ch9))
print('ASCII value of', ch10, 'is', ord(ch10))
print('ASCII value of', ch11, 'is', ord(ch11))
print('ASCII value of', ch12, 'is', ord(ch12))

Sortir:

ASCII value of M is 77
ASCII value of U is 85
ASCII value of O is 79
ASCII value of m is 109
ASCII value of a is 97
ASCII value of k is 107
ASCII value of e is 101
ASCII value of u is 117
ASCII value of s is 115
ASCII value of e is 101
ASCII value of o is 111
ASCII value of f is 102

Programme JavaScript pour trouver la valeur ASCII d'un caractère

Vous pouvez trouver la valeur ASCII d'un caractère en utilisant string.charCodeAt(0) en JavaScript. Ci-dessous se trouve le programme JavaScript pour imprimer la valeur ASCII d'un caractère :

const ch1 = 'M';
const ch2 = 'U';
const ch3 = 'O';
const ch4 = 'm';
const ch5 = 'a';
const ch6 = 'k';
const ch7 = 'e';
const ch8 = 'u';
const ch9 = 's';
const ch10 = 'e';
const ch11 = 'o';
const ch12 = 'f';

// string.charCodeAt(0) is used to convert character to its ASCII value
document.write('ASCII value of ' + ch1+ ' is ' + ch1.charCodeAt(0) + '
');
document.write('ASCII value of ' + ch2+ ' is ' + ch2.charCodeAt(0) + '
');
document.write('ASCII value of ' + ch3+ ' is ' + ch3.charCodeAt(0) + '
');
document.write('ASCII value of ' + ch4+ ' is ' + ch4.charCodeAt(0) + '
');
document.write('ASCII value of ' + ch5+ ' is ' + ch5.charCodeAt(0) + '
');
document.write('ASCII value of ' + ch6+ ' is ' + ch6.charCodeAt(0) + '
');
document.write('ASCII value of ' + ch7+ ' is ' + ch7.charCodeAt(0) + '
');
document.write('ASCII value of ' + ch8+ ' is ' + ch8.charCodeAt(0) + '
');
document.write('ASCII value of ' + ch9+ ' is ' + ch9.charCodeAt(0) + '
');
document.write('ASCII value of ' + ch10+ ' is ' + ch10.charCodeAt(0) + '
');
document.write('ASCII value of ' + ch11+ ' is ' + ch11.charCodeAt(0) + '
');
document.write('ASCII value of ' + ch12+ ' is ' + ch12.charCodeAt(0) + '
');

Sortir:

ASCII value of M is 77
ASCII value of U is 85
ASCII value of O is 79
ASCII value of m is 109
ASCII value of a is 97
ASCII value of k is 107
ASCII value of e is 101
ASCII value of u is 117
ASCII value of s is 115
ASCII value of e is 101
ASCII value of o is 111
ASCII value of f is 102

Connexes : Comment créer une calculatrice simple à l'aide de HTML, CSS et JavaScript

C Programme pour trouver la valeur ASCII d'un caractère

Vous pouvez trouver la valeur ASCII d'un caractère en utilisant spécificateurs de format en C. Ci-dessous se trouve le programme C pour imprimer la valeur ASCII d'un caractère :

// C program to find the ASCII value of a character
#include
int main()
{
char ch1 = 'M';
char ch2 = 'U';
char ch3 = 'O';
char ch4 = 'm';
char ch5 = 'a';
char ch6 = 'k';
char ch7 = 'e';
char ch8 = 'u';
char ch9 = 's';
char ch10 = 'e';
char ch11 = 'o';
char ch12 = 'f';
// You can print the ASCII value of a character in C using format specifier
// %d displays the integer ASCII value of a character
// %c displays the character itself
printf('ASCII value of %c is %d ⁠n', ch1, ch1);
printf('ASCII value of %c is %d ⁠n', ch2, ch2);
printf('ASCII value of %c is %d ⁠n', ch3, ch3);
printf('ASCII value of %c is %d ⁠n', ch4, ch4);
printf('ASCII value of %c is %d ⁠n', ch5, ch5);
printf('ASCII value of %c is %d ⁠n', ch6, ch6);
printf('ASCII value of %c is %d ⁠n', ch7, ch7);
printf('ASCII value of %c is %d ⁠n', ch8, ch8);
printf('ASCII value of %c is %d ⁠n', ch9, ch9);
printf('ASCII value of %c is %d ⁠n', ch10, ch10);
printf('ASCII value of %c is %d ⁠n', ch11, ch11);
printf('ASCII value of %c is %d ⁠n', ch12, ch12);
return 0;
}

Sortir:

ASCII value of M is 77
ASCII value of U is 85
ASCII value of O is 79
ASCII value of m is 109
ASCII value of a is 97
ASCII value of k is 107
ASCII value of e is 101
ASCII value of u is 117
ASCII value of s is 115
ASCII value of e is 101
ASCII value of o is 111
ASCII value of f is 102

Développez vos compétences en programmation de manière amusante et pratique

La programmation est amusante une fois que vous vous êtes amélioré et que vous savez ce que vous faites. Vous pouvez apprendre la programmation de plusieurs manières. Mais la méthode pratique d'apprentissage de la programmation peut vous aider à apprendre plus rapidement et à conserver les informations plus longtemps.

Building Coding Games est l'une des meilleures méthodes pour acquérir une expérience pratique tout en s'amusant en même temps.

Partager Partager Tweeter E-mail Les 9 meilleurs jeux de codage pour développer vos compétences en programmation

Les jeux de codage vous aident à apprendre plus rapidement grâce à une pratique et à une expérience pratiques. De plus, c'est une façon amusante de tester vos compétences en programmation !

Lire la suite
Rubriques connexes
  • La programmation
  • JavaScript
  • Python
  • Tutoriels de codage
  • C Programmation
A propos de l'auteur Yuvraj Chandra(60 articles publiés)

Yuvraj est un étudiant de premier cycle en informatique à l'Université de Delhi, en Inde. Il est passionné par le développement Web Full Stack. Quand il n'écrit pas, il explore la profondeur de différentes technologies.

Plus de Yuvraj Chandra

Abonnez-vous à notre newsletter

Rejoignez notre newsletter pour des conseils techniques, des critiques, des ebooks gratuits et des offres exclusives !

Cliquez ici pour vous abonner