Wie finden Sie den ASCII-Wert eines Zeichens?

Wie finden Sie den ASCII-Wert eines Zeichens?

„ASCII“ steht für „American Standard Code for Information Interchange“. ASCII-Codes repräsentieren Text in Computern, Telekommunikationsgeräten und anderen Geräten. ASCII wandelt Informationen in standardisierte digitale Formate um, die es Computern ermöglichen, Daten zu verarbeiten, Daten zu speichern und effizient mit anderen Computern zu kommunizieren.





In diesem Artikel erfahren Sie, wie Sie mit C++, Python, JavaScript und C den ASCII-Wert eines Zeichens ermitteln.





Best Practices für Windows 10-Gruppenrichtlinien

Problemstellung

Sie erhalten ein Zeichen und müssen den ASCII-Wert dieses Zeichens ausgeben.





Beispiel 1 : Das angegebene Zeichen sei 'M'.

Der ASCII-Wert von 'M' ist 77.



Somit ist die Ausgabe 77.

Beispiel 2 : Das angegebene Zeichen sei 'U'.





Der ASCII-Wert von 'U' ist 85.

Somit beträgt die Ausgabe 85.





Beispiel 3 : Das angegebene Zeichen sei 'O'.

Der ASCII-Wert von 'O' ist 79.

Somit ist die Ausgabe 79.

Wenn Sie sich die komplette ASCII-Tabelle ansehen möchten, können Sie es sich ansehen Website von asciitable .

Verwandt: Was ist der Unterschied zwischen ASCII- und Unicode-Text?

C++-Programm zum Ermitteln des ASCII-Werts eines Zeichens

Den ASCII-Wert eines Zeichens finden Sie mit int() in C++. Unten ist das C++-Programm zum Drucken des ASCII-Werts eines Zeichens:

Übertragen Sie Dateien vom PC auf das Android-WLAN direkt
// 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;
}

Ausgabe:

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

Verwandt: Was ist ASCII-Text und wie wird er verwendet?

Python-Programm zum Ermitteln des ASCII-Werts eines Zeichens

Den ASCII-Wert eines Zeichens finden Sie mit Wörter() bei Python. Unten ist das Python-Programm zum Drucken des ASCII-Werts eines Zeichens:

# 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))

Ausgabe:

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

JavaScript-Programm zum Ermitteln des ASCII-Werts eines Zeichens

Den ASCII-Wert eines Zeichens finden Sie mit string.charCodeAt(0) in JavaScript. Unten ist das JavaScript-Programm zum Drucken des ASCII-Werts eines Zeichens:

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) + '
');

Ausgabe:

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

Verwandte: So erstellen Sie einen einfachen Rechner mit HTML, CSS und JavaScript

C-Programm zum Ermitteln des ASCII-Werts eines Zeichens

Den ASCII-Wert eines Zeichens finden Sie mit Formatbezeichner in C. Unten ist das C-Programm zum Drucken des ASCII-Werts eines Zeichens:

// 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;
}

Ausgabe:

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

Bauen Sie Ihre Programmierfähigkeiten auf unterhaltsame und praktische Weise aus

Programmieren macht Spaß, wenn man es besser kann und weiß, was man tut. Programmieren kann man auf verschiedene Weise lernen. Aber die praktische Methode des Programmierens kann Ihnen helfen, schneller zu lernen und die Informationen über einen längeren Zeitraum zu behalten.

Das Erstellen von Programmierspielen ist eine der besten Methoden, um praktische Erfahrungen zu sammeln und gleichzeitig Spaß zu haben.

Teilen Teilen Tweet Email Die 9 besten Programmierspiele zum Aufbau Ihrer Programmierfähigkeiten

Programmierspiele helfen Ihnen, durch praktische Übung und Erfahrung schneller zu lernen. Außerdem sind sie eine unterhaltsame Möglichkeit, Ihre Programmierfähigkeiten zu testen!

Weiter lesen
Verwandte Themen
  • Programmierung
  • JavaScript
  • Python
  • Codierungs-Tutorials
  • C-Programmierung
Über den Autor Yuvraj Chandra(60 veröffentlichte Artikel)

Yuvraj studiert Informatik an der University of Delhi, Indien. Seine Leidenschaft gilt der Full-Stack-Webentwicklung. Wenn er nicht gerade schreibt, erforscht er die Tiefe verschiedener Technologien.

Mehr von Yuvraj Chandra

Abonniere unseren Newsletter

Abonnieren Sie unseren Newsletter für technische Tipps, Rezensionen, kostenlose E-Books und exklusive Angebote!

Klicken Sie hier, um zu abonnieren