
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 a String to Hexadecimal ASCII Values in C++
In this tutorial, we will be discussing a program to convert a string to hexadecimal ASCII values.
For this we will be provided with a string of characters. Our task is to print that particular given string into its hexadecimal equivalent.
Example
#include <stdio.h> #include <string.h> //converting string to hexadecimal void convert_hexa(char* input, char* output){ int loop=0; int i=0; while(input[loop] != '\0'){ sprintf((char*)(output+i),"%02X", input[loop]); loop+=1; i+=2; } //marking the end of the string output[i++] = '\0'; } int main(){ char ascii_str[] = "tutorials point"; int len = strlen(ascii_str); char hex_str[(len*2)+1]; //function call convert_hexa(ascii_str, hex_str); printf("ASCII: %s\n", ascii_str); printf("Hexadecimal: %s\n", hex_str); return 0; }
Output
ASCII: tutorials point Hexadecimal: 7475746F7269616C7320706F696E74
Advertisements