Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert Hexadecimal value String to ASCII value String in C++
In this tutorial, we will be discussing a program to convert hexadecimal value string to ASCII value string.
For this we will be provided with a string with some hexadecimal values. Our task is to get that hexadecimal value and convert it into equivalent ASCII values.
Example
#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;
}
Output
avengers
Advertisements