Encode your text into ASCII HEX code using C
20 Jan 2013This C++ code will convert the typing keystrokes from keyboard into ASCII code(HEX).
#include<stdio.h>
#include<conio.h>
char HEXST(char a){
int rem,no=int(a),i=0;
char tmp,string[2];
while(no>0){
rem=no%16;
no=(no/16);
switch(rem){
case 0:
tmp='A';
break;
case 1:
tmp='B';
break;
case 2:
tmp='C';
break;
case 3:
tmp='D';
break;
case 4:
tmp='E';
break;
case 5:
tmp='F';
break;
default:
tmp=rem;
}
string[i]=tmp;
i++;
}
for(int y=1;y>=0;y--){
if(string[y]<65||string[y]>122)
printf("%d",string[y]);
else
printf("%c",string[y]);
}
}
void HEXS()
{
char typed;
printf("Enter Words and Corresponding Hex will be displayed\n=======================================\n\n\nPress Esc twice to quit");
while(typed!=27){
typed=getch();
printf("\n%c\t",typed);
HEXST(typed);
}
getch();
}
void main()
{
HEXS();
}