Bagaimana Anda Menemui Nilai ASCII Perwatakan?

Bagaimana Anda Menemui Nilai ASCII Perwatakan?

'ASCII' bermaksud 'American Standard Code for Information Interchange'. Kod ASCII mewakili teks dalam komputer, peralatan telekomunikasi, dan peranti lain. ASCII mengubah maklumat menjadi format digital standard yang membolehkan komputer memproses data, menyimpan data, dan berkomunikasi dengan cekap dengan komputer lain.





Dalam artikel ini, anda akan belajar bagaimana mencari nilai ASCII watak menggunakan C ++, Python, JavaScript, dan C.





bilakah ps4 slim keluar

Pernyataan masalah

Anda diberi watak dan anda perlu mencetak nilai ASCII watak itu.





Contoh 1 : Biarkan watak yang diberi menjadi 'M'.

Nilai ASCII bagi 'M' ialah 77.



Oleh itu, output adalah 77.

Contoh 2 : Biarkan watak yang diberi menjadi 'U'.





Nilai ASCII bagi 'U' adalah 85.

Oleh itu, outputnya adalah 85.





Contoh 3 : Biarkan watak yang diberi menjadi 'O'.

Nilai ASCII 'O' ialah 79.

Oleh itu, output adalah 79.

Sekiranya anda ingin melihat jadual ASCII yang lengkap, anda boleh melihatnya laman web asciitable .

Berkaitan: Apakah Perbezaan Antara Teks ASCII dan Unicode?

Program C ++ untuk Mencari Nilai ASCII Perwatakan

Anda boleh menemui nilai ASCII watak menggunakan int () dalam C ++. Berikut adalah program C ++ untuk mencetak nilai ASCII watak:

berapa lama bekalan kuasa komputer bertahan
// 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;
}

Pengeluaran:

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

Berkaitan: Apakah Teks ASCII dan Bagaimana Ia Digunakan?

Program Python untuk Mencari Nilai ASCII Perwatakan

Anda boleh menemui nilai ASCII watak menggunakan perkataan () di Python. Berikut adalah program Python untuk mencetak nilai ASCII watak:

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

Pengeluaran:

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

Program JavaScript untuk Mencari Nilai ASCII Karakter

Anda boleh menemui nilai ASCII watak menggunakan string.charCodeAt (0) dalam JavaScript. Berikut adalah program JavaScript untuk mencetak nilai ASCII watak:

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

Pengeluaran:

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

Berkaitan: Cara Membangun Kalkulator Mudah Menggunakan HTML, CSS, dan JavaScript

Program C untuk Mencari Nilai ASCII Perwatakan

Anda boleh menemui nilai ASCII watak menggunakan penentu format di C. Berikut adalah program C untuk mencetak nilai ASCII watak:

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

Pengeluaran:

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

Bina Kemahiran Pengaturcaraan Anda dengan Cara Praktikal yang Menyeronokkan

Pengaturcaraan sangat menyeronokkan apabila anda menjadi lebih mahir dan mengetahui apa yang anda lakukan. Anda boleh belajar pengaturcaraan dengan beberapa cara. Tetapi kaedah pengaturcaraan pembelajaran langsung dapat membantu anda belajar lebih cepat dan mengekalkan maklumat untuk jangka masa yang lebih lama.

Building Coding Games adalah salah satu kaedah terbaik untuk mendapatkan pengalaman sambil bersenang-senang pada masa yang sama.

Berkongsi Berkongsi Tweet E-mel 9 Permainan Pengekodan Terbaik untuk Membina Kemahiran Mengaturcara Anda

Permainan pengekodan membantu anda belajar lebih cepat dengan latihan dan pengalaman langsung. Selain itu, mereka adalah kaedah yang menyeronokkan untuk menguji kemahiran pengaturcaraan anda!

Baca Seterusnya
Topik-topik yang berkaitan
  • Pengaturcaraan
  • JavaScript
  • Python
  • Tutorial Pengekodan
  • Pengaturcaraan C
Mengenai Pengarang Yuvraj Chandra(60 Artikel Diterbitkan)

Yuvraj adalah pelajar sarjana Sains Komputer di University of Delhi, India. Dia meminati Pembangunan Web Stack Penuh. Ketika dia tidak menulis, dia meneroka kedalaman teknologi yang berbeza.

Lagi Dari Yuvraj Chandra

Langgan buletin kami

Sertailah buletin kami untuk mendapatkan petua, ulasan, ebook percuma, dan tawaran eksklusif!

Klik di sini untuk melanggan