使用 ASCII 查找表实现 C++ 程序
在本教程中,我们将讨论一个使用 ASCII 查找表的程序。
ASCII 查找表是一种表格表示法,为给定字符提供八进制、十六进制、十进制和 HTML 值。
ASCII 查找表的字符包括字母、数字、分隔符和特殊符号。
示例
#include <iostream>
#include <string>
using namespace std;
//converting decimal value to octal
int Octal(int decimal){
int octal = 0;
string temp = "";
while (decimal > 0) {
int remainder = decimal % 8;
temp = to_string(remainder) + temp;
decimal /= 8;
}
for (int i = 0; i < temp.length(); i++)
octal = (octal * 10) + (temp[i] - '0');
return octal;
}
//converting decimal value to hexadecimal
string Hexadecimal(int decimal){
string hex = "";
while (decimal > 0) {
int remainder = decimal % 16;
if (remainder >= 0 && remainder <= 9)
hex = to_string(remainder) + hex;
else
hex = (char)('A' + remainder % 10) + hex;
decimal /= 16;
}
return hex;
}
//converting decimal value to HTML
string HTML(int decimal){
string html = to_string(decimal);
html = "&#" + html + ";";
return html;
}
//calculating the ASCII lookup table
void ASCIIlookuptable(char ch){
int decimal = ch;
cout << "Octal value: " << Octal(decimal) << endl;
cout << "Decimal value: " << decimal << endl;
cout << "Hexadecimal value: " << Hexadecimal(decimal) <<
endl;
cout << "HTML value: " << HTML(decimal);
}
int main(){
char ch = 'a';
ASCIIlookuptable(ch);
return 0;
}输出
Octal value: 141 Decimal value: 97 Hexadecimal value: 61 HTML value: a
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP