Function to read HEX and Print ASCII

is there a function or something that take HEX and print it's corresponding ASCII Character ..
Here is my Code to take Character Array [4] and Print it's HEX to File ..
but i don't know how to reverse ! ? and ideas ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;

int main()
{
    char buffer[4];
    memset(buffer,0,4);
    fstream FILE( "File.dat" ,ios::in | ios::out | ios::binary | ios::trunc);

    cin.read(buffer,4);

    for(int i=0; i<4; i++)
    {
        FILE<<hex<<(int)buffer[i];
    }
  FILE.close();
}

1
2
3
4
5
6
7
8
9
#include <iostream>
#include <iomanip>

int main()
{
    int inp;
    std::cin >> std::hex >> inp;
    std::cout << static_cast<char>(inp);
}
4E
N
Last edited on
Topic archived. No new replies allowed.