將十六進位制值字串轉換為 C++ 中的 ASCII 值字串
在本次教程中,我們將討論一個程式,用於將十六進位制值字串轉換為 ASCII 值字串。
首先,我們將使用一個包含一些十六進位制值的字串。我們的任務是獲取該十六進位制值並將其轉換為等效的 ASCII 值。
示例
#include <bits/stdc++.h>
using namespace std;
string convert_ASCII(string hex){
string ascii = "";
for (size_t i = 0; i < hex.length(); i += 2){
//taking two characters from hex string
string part = hex.substr(i, 2);
//changing it into base 16
char ch = stoul(part, nullptr, 16);
//putting it into the ASCII string
ascii += ch;
}
return ascii;
}
int main(){
cout << convert_ASCII("6176656e67657273") << endl;
return 0;
}輸出
avengers
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP