Come si trova il valore ASCII di un carattere?

Come si trova il valore ASCII di un carattere?

'ASCII' sta per 'American Standard Code for Information Interchange'. I codici ASCII rappresentano il testo in computer, apparecchiature di telecomunicazione e altri dispositivi. ASCII converte le informazioni in formati digitali standardizzati che consentono ai computer di elaborare dati, archiviare dati e comunicare in modo efficiente con altri computer.





In questo articolo imparerai come trovare il valore ASCII di un carattere usando C++, Python, JavaScript e C.





come ottenere gratuitamente Office 365

Dichiarazione problema

Ti viene assegnato un carattere e devi stampare il valore ASCII di quel carattere.





Esempio 1 : Lascia che il carattere dato sia 'M'.

Il valore ASCII di 'M' è 77.



Quindi, l'output è 77.

Esempio 2 : Lascia che il carattere dato sia 'U'.





Il valore ASCII di 'U' è 85.

Pertanto, l'output è 85.





Esempio 3 : Lascia che il carattere dato sia 'O'.

Il valore ASCII di 'O' è 79.

Pertanto, l'output è 79.

Se vuoi dare un'occhiata alla tabella ASCII completa, puoi dare un'occhiata sito web di asciitable .

Imparentato: Qual è la differenza tra ASCII e testo Unicode?

Programma C++ per trovare il valore ASCII di un carattere

Puoi trovare il valore ASCII di un carattere usando intero() in C++. Di seguito è riportato il programma C++ per stampare il valore ASCII di un carattere:

come faccio a eliminare il mio account di posta elettronica?
// 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;
}

Produzione:

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

Imparentato: Che cos'è il testo ASCII e come viene utilizzato?

Programma Python per trovare il valore ASCII di un carattere

Puoi trovare il valore ASCII di un carattere usando parole() in Pitone. Di seguito è riportato il programma Python per stampare il valore ASCII di un carattere:

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

Produzione:

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

Programma JavaScript per trovare il valore ASCII di un carattere

Puoi trovare il valore ASCII di un carattere usando string.charCodeAt(0) in JavaScript. Di seguito è riportato il programma JavaScript per stampare il valore ASCII di un carattere:

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

Produzione:

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

Correlati: Come costruire una calcolatrice semplice utilizzando HTML, CSS e JavaScript

Programma C per trovare il valore ASCII di un carattere

Puoi trovare il valore ASCII di un carattere usando identificatori di formato in C. Di seguito il programma C per stampare il valore ASCII di un carattere:

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

Produzione:

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

Sviluppa le tue abilità di programmazione in modi divertenti e pratici

La programmazione è divertente una volta che si diventa più bravi e si sa cosa si sta facendo. Puoi imparare a programmare in diversi modi. Ma il metodo pratico di apprendimento della programmazione può aiutarti a imparare più velocemente e a conservare le informazioni per un periodo di tempo più lungo.

Costruire giochi di codice è uno dei metodi migliori per ottenere un'esperienza pratica divertendosi allo stesso tempo.

Condividere Condividere Tweet E-mail I 9 migliori giochi di programmazione per sviluppare le tue abilità di programmazione

I giochi di programmazione ti aiutano a imparare più velocemente con la pratica e l'esperienza pratica. Inoltre, sono un modo divertente per testare le tue abilità di programmazione!

Leggi Avanti
Argomenti correlati
  • Programmazione
  • JavaScript
  • Pitone
  • Tutorial sulla programmazione
  • C Programmazione
Circa l'autore Yuvraj Chandra(60 articoli pubblicati)

Yuvraj è uno studente universitario di Informatica presso l'Università di Delhi, in India. È appassionato di sviluppo Web Full Stack. Quando non scrive, esplora la profondità di diverse tecnologie.

Altro da Yuvraj Chandra

Iscriviti alla nostra Newsletter

Iscriviti alla nostra newsletter per suggerimenti tecnici, recensioni, ebook gratuiti e offerte esclusive!

Clicca qui per iscriverti