C++ ascii to hex and hex to ascii converter

#include <string.h>
#include <stdio.h>
#include <iostream>
#include <cmath>
using namespace std;

const char hexmap[] = {'0', '1', '2', '3', '4', '5', '6', '7',
                           '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

static void ascii2hex(char *asc, char *hexout)
{
  for (int i = 0; i < strlen(asc); ++i) {
    hexout[2 * i]     = hexmap[(asc[i] & 0xF0) >> 4];
    hexout[2 * i + 1] = hexmap[asc[i] & 0x0F];
  }
}//ascii2hex  
              
static void hex2ascii(char *hexStr, char *asciiString) {
                
    size_t len = strlen(hexStr);
    int k=0;
           
    for (size_t i = 0; i < len; i+=2)
    {
        asciiString[k++] = (((hexStr[i] >= 'A')? (hexStr[i] - 'A' + 10): (hexStr[i] - '0')) << 4) |
                      (((hexStr[i+1] >= 'A')? (hexStr[i+1] - 'A' + 10): (hexStr[i+1] - '0')));
    }
    asciiString[k] = '\0';
           
}//hex2ascii

int main () {

char a[]="HI EVERYBODY";

cout << a << endl;

char *b = new char [ (strlen(a) * 2) + 1 ];

ascii2hex(a,b);

cout << "ascii2hex:\n" << b << "\nSIZE:" << strlen(b) << endl;

char *c = new char [ (strlen(b) /2 ) + 1 ];
hex2ascii(b,c);
cout << "hex2ascii:\n" << c << "\nSIZE:" << strlen(c) << endl;


delete [] b;
delete [] c;

}//main

By: Mehdi Sadighian
Contact: mehdi.sadighian@hotmail.com
TAG: C, C++, ascii to hex, hex to ascii, char array