Convert Hexadecimal value String to ASCII value String
Last Updated :
11 Jul, 2025
Given the Hexadecimal value string as input, the task is to convert the given hexadecimal value string into its corresponding ASCII format string.
Examples:
Input: 6765656b73
Output: geeks
Input: 6176656e67657273
Output: avengers
The “Hexadecimal” or simply “Hex” numbering system uses the Base of 16 system. Being a Base-16 system, there are 16 possible digit symbols. The hexadecimal number uses 16 symbols {0, 1, 2, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F} to represent all numbers. Here, (A, B, C, D, E, F) represents (10, 11, 12, 13, 14, 15).
ASCII stands for American Standard Code for Information Interchange. ASCII is a standard that assigns letters, numbers, and other characters within the 256 slots available in the 8-bit code. E.g the lower case "h" character (Char) has a decimal value of 104, which is "01101000" in binary and “68” in hexadecimal.
Algorithm:
- Initialize final ascii string as empty.
- Extract first two characters from the hexadecimal string taken as input.
- Convert it into base 16 integer.
- Cast this integer to character which is ASCII equivalent of 2 char hex.
- Add this character to final string.
- Extract next two characters from hexadecimal string and go to step 3.
- Follow these steps to extract all characters from hexadecimal string.

Implementation:
C++
// C++ program to convert hexadecimal
// string to ASCII format string
#include <bits/stdc++.h>
using namespace std;
string hexToASCII(string hex)
{
// initialize the ASCII code string as empty.
string ascii = "";
for (size_t i = 0; i < hex.length(); i += 2)
{
// extract two characters from hex string
string part = hex.substr(i, 2);
// change it into base 16 and
// typecast as the character
char ch = stoul(part, nullptr, 16);
// add this char to final ASCII string
ascii += ch;
}
return ascii;
}
// Driver Code
int main()
{
// print the ASCII string.
cout << hexToASCII("6765656b73") << endl;
return 0;
}
// This code is contributed by
// sanjeev2552
Java
// Java program to convert hexadecimal
// string to ASCII format string
import java.util.Scanner;
public class HexadecimalToASCII {
public static String hexToASCII(String hex)
{
// initialize the ASCII code string as empty.
String ascii = "";
for (int i = 0; i < hex.length(); i += 2) {
// extract two characters from hex string
String part = hex.substring(i, i + 2);
// change it into base 16 and typecast as the character
char ch = (char)Integer.parseInt(part, 16);
// add this char to final ASCII string
ascii = ascii + ch;
}
return ascii;
}
public static void main(String[] args)
{
// print the ASCII string.
System.out.println(hexToASCII("6765656b73"));
}
}
Python3
# Python3 program to convert hexadecimal
# string to ASCII format string
def hexToASCII(hexx):
# initialize the ASCII code string as empty.
ascii = ""
for i in range(0, len(hexx), 2):
# extract two characters from hex string
part = hexx[i : i + 2]
# change it into base 16 and
# typecast as the character
ch = chr(int(part, 16))
# add this char to final ASCII string
ascii += ch
return ascii
# Driver Code
if __name__ == "__main__":
# print the ASCII string.
print(hexToASCII("6765656b73"))
# This code is contributed by
# sanjeev2552
C#
// C# program to convert hexadecimal
// string to ASCII format string
using System;
class GFG
{
public static String hexToASCII(String hex)
{
// initialize the ASCII code string as empty.
String ascii = "";
for (int i = 0; i < hex.Length; i += 2)
{
// extract two characters from hex string
String part = hex.Substring(i, 2);
// change it into base 16 and
// typecast as the character
char ch = (char)Convert.ToInt32(part, 16);;
// add this char to final ASCII string
ascii = ascii + ch;
}
return ascii;
}
// Driver Code
public static void Main(String[] args)
{
// print the ASCII string.
Console.WriteLine(hexToASCII("6765656b73"));
}
}
// This code is contributed by PrinciRaj1992
JavaScript
<script>
// JavaScript program to convert hexadecimal
// string to ASCII format string
function hexToASCII(hex) {
// initialize the ASCII code string as empty.
var ascii = "";
for (var i = 0; i < hex.length; i += 2) {
// extract two characters from hex string
var part = hex.substring(i, i + 2);
// change it into base 16 and
// typecast as the character
var ch = String.fromCharCode(parseInt(part, 16));
// add this char to final ASCII string
ascii = ascii + ch;
}
return ascii;
}
// Driver Code
// print the ASCII string.
document.write(hexToASCII("6765656b73"));
</script>
Time complexity: O(N), where N is the length of the given string
Auxiliary space: O(N)
Approach 2: Using Bitwise Operations:
This approach is to use bitwise operations to directly convert the hexadecimal string to an ASCII string. In this approach, we would start by converting the hexadecimal string to a series of bytes. We can do this by iterating through the string and converting each pair of hexadecimal digits to a byte. Once we have the bytes, we can use bitwise operations to convert them to characters in the ASCII string.
In this implementation, we use a stringstream to build the ASCII string. We iterate through the hexadecimal string, converting each pair of hexadecimal digits to a byte using stoi. Then, we append the byte to the stringstream. Finally, we return the contents of the stringstream as the ASCII string.
Here is the code of this approach:
C++
#include <bits/stdc++.h>
using namespace std;
string hexToASCII(std::string hex) {
stringstream ss;
for (size_t i = 0; i < hex.length(); i += 2) {
unsigned char byte =stoi(hex.substr(i, 2), nullptr, 16);
ss << byte;
}
return ss.str();
}
int main() {
string hexString = "6765656b73";
string asciiString = hexToASCII(hexString);
cout << asciiString << endl;
return 0;
}
Java
import java.util.*;
public class HexToASCII {
public static String hexToASCII(String hex) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hex.length(); i += 2) {
String str = hex.substring(i, i + 2);
char ch = (char) Integer.parseInt(str, 16);
sb.append(ch);
}
return sb.toString();
}
public static void main(String[] args) {
String hexString = "6765656b73";
String asciiString = hexToASCII(hexString);
System.out.println(asciiString);
}
}
Python3
def hex_to_ascii(hex_str):
ascii_str = ""
for i in range(0, len(hex_str), 2):
byte = int(hex_str[i:i+2], 16)
ascii_str += chr(byte)
return ascii_str
# Driver code
hex_string = "6765656b73"
ascii_string = hex_to_ascii(hex_string)
print(ascii_string)
C#
using System;
using System.Text;
public class Program
{
public static string HexToASCII(string hex)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hex.Length; i += 2)
{
byte b = Convert.ToByte(hex.Substring(i, 2), 16);
sb.Append((char)b);
}
return sb.ToString();
}
public static void Main()
{
string hexString = "6765656b73";
string asciiString = HexToASCII(hexString);
Console.WriteLine(asciiString);
}
}
// This code is contributed by Prajwal Kandekar
JavaScript
// Javascript code addition
function hexToASCII(hex) {
let sb = "";
for (let i = 0; i < hex.length; i += 2) {
let str = hex.substring(i, i + 2);
let ch = String.fromCharCode(parseInt(str, 16));
sb += ch;
}
return sb;
}
let hexString = "6765656b73";
let asciiString = hexToASCII(hexString);
console.log(asciiString);
// The code is contributed by Nidhi goel.
Output
geeks
Time complexity: O(n), where N is the length of the given string
Auxiliary space: O(n)
Similar Reads
Basics & Prerequisites
Data Structures
Array Data StructureIn this article, we introduce array, implementation in different popular languages, its basic operations and commonly seen problems / interview questions. An array stores items (in case of C/C++ and Java Primitive Arrays) or their references (in case of Python, JS, Java Non-Primitive) at contiguous
3 min read
String in Data StructureA string is a sequence of characters. The following facts make string an interesting data structure.Small set of elements. Unlike normal array, strings typically have smaller set of items. For example, lowercase English alphabet has only 26 characters. ASCII has only 256 characters.Strings are immut
2 min read
Hashing in Data StructureHashing is a technique used in data structures that efficiently stores and retrieves data in a way that allows for quick access. Hashing involves mapping data to a specific index in a hash table (an array of items) using a hash function. It enables fast retrieval of information based on its key. The
2 min read
Linked List Data StructureA linked list is a fundamental data structure in computer science. It mainly allows efficient insertion and deletion operations compared to arrays. Like arrays, it is also used to implement other data structures like stack, queue and deque. Hereâs the comparison of Linked List vs Arrays Linked List:
2 min read
Stack Data StructureA Stack is a linear data structure that follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out). LIFO implies that the element that is inserted last, comes out first and FILO implies that the element that is inserted first
2 min read
Queue Data StructureA Queue Data Structure is a fundamental concept in computer science used for storing and managing data in a specific order. It follows the principle of "First in, First out" (FIFO), where the first element added to the queue is the first one to be removed. It is used as a buffer in computer systems
2 min read
Tree Data StructureTree Data Structure is a non-linear data structure in which a collection of elements known as nodes are connected to each other via edges such that there exists exactly one path between any two nodes. Types of TreeBinary Tree : Every node has at most two childrenTernary Tree : Every node has at most
4 min read
Graph Data StructureGraph Data Structure is a collection of nodes connected by edges. It's used to represent relationships between different entities. If you are looking for topic-wise list of problems on different topics like DFS, BFS, Topological Sort, Shortest Path, etc., please refer to Graph Algorithms. Basics of
3 min read
Trie Data StructureThe Trie data structure is a tree-like structure used for storing a dynamic set of strings. It allows for efficient retrieval and storage of keys, making it highly effective in handling large datasets. Trie supports operations such as insertion, search, deletion of keys, and prefix searches. In this
15+ min read
Algorithms
Searching AlgorithmsSearching algorithms are essential tools in computer science used to locate specific items within a collection of data. In this tutorial, we are mainly going to focus upon searching in an array. When we search an item in an array, there are two most common algorithms used based on the type of input
2 min read
Sorting AlgorithmsA Sorting Algorithm is used to rearrange a given array or list of elements in an order. For example, a given array [10, 20, 5, 2] becomes [2, 5, 10, 20] after sorting in increasing order and becomes [20, 10, 5, 2] after sorting in decreasing order. There exist different sorting algorithms for differ
3 min read
Introduction to RecursionThe process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called a recursive function. A recursive algorithm takes one step toward solution and then recursively call itself to further move. The algorithm stops once we reach the solution
14 min read
Greedy AlgorithmsGreedy algorithms are a class of algorithms that make locally optimal choices at each step with the hope of finding a global optimum solution. At every step of the algorithm, we make a choice that looks the best at the moment. To make the choice, we sometimes sort the array so that we can always get
3 min read
Graph AlgorithmsGraph is a non-linear data structure like tree data structure. The limitation of tree is, it can only represent hierarchical data. For situations where nodes or vertices are randomly connected with each other other, we use Graph. Example situations where we use graph data structure are, a social net
3 min read
Dynamic Programming or DPDynamic Programming is an algorithmic technique with the following properties.It is mainly an optimization over plain recursion. Wherever we see a recursive solution that has repeated calls for the same inputs, we can optimize it using Dynamic Programming. The idea is to simply store the results of
3 min read
Bitwise AlgorithmsBitwise algorithms in Data Structures and Algorithms (DSA) involve manipulating individual bits of binary representations of numbers to perform operations efficiently. These algorithms utilize bitwise operators like AND, OR, XOR, NOT, Left Shift, and Right Shift.BasicsIntroduction to Bitwise Algorit
4 min read
Advanced
Segment TreeSegment Tree is a data structure that allows efficient querying and updating of intervals or segments of an array. It is particularly useful for problems involving range queries, such as finding the sum, minimum, maximum, or any other operation over a specific range of elements in an array. The tree
3 min read
Pattern SearchingPattern searching algorithms are essential tools in computer science and data processing. These algorithms are designed to efficiently find a particular pattern within a larger set of data. Patten SearchingImportant Pattern Searching Algorithms:Naive String Matching : A Simple Algorithm that works i
2 min read
GeometryGeometry is a branch of mathematics that studies the properties, measurements, and relationships of points, lines, angles, surfaces, and solids. From basic lines and angles to complex structures, it helps us understand the world around us.Geometry for Students and BeginnersThis section covers key br
2 min read
Interview Preparation
Practice Problem