
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
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
- Related Articles
- Convert Hexadecimal value String to ASCII value String in C++
- C program to print the ASCII values in a string.
- Converting ASCII to hexadecimal in JavaScript
- Convert a Number to Hexadecimal in C++
- Convert the ASCII value sentence to its equivalent string in C++
- How to convert an integer to a hexadecimal string in Python?
- Count characters in a string whose ASCII values are prime in C++
- Java Program to convert ASCII code to String
- How to Convert a String to Hexadecimal and vice versa format in java?
- Convert an int to ASCII character in C/C++
- Program to convert IP address to hexadecimal in C++
- Program to Convert Hexadecimal to Octal in C program
- 8085 Program to convert two-digit hex to two ASCII values
- C++ Program to Convert Hexadecimal Number to Binary
- Represent Int32 as a Hexadecimal String in C#

Advertisements