0

So I'm trying to write a program that will read a program that will be reading characters/strings in regular text and will output the information in hexadecimal format. An example of such is this "UNAME" = "55 4E 41 4D 45 28 31 29" in hexadecimal format. I just don't know where to start, any ideas?

5
Contributors
5
Replies
22
Views
3 Years
Discussion Span
Last Post by naveen1993
0

Characters are 8 bit integers. Use the appropriate printf format strings. To output the hex value of a character you would use %.02x

0

try this:-

char arr[]={"UNAME"};
for(int i=0;arr[i]!=NULL;i++)
{
printf("%x\t",arr[i]); //this is what you want
}

hope this may help you , however i am not much familiar with c programing .

1

To me "UNAME" converts to hex as "55 4E 41 4D 45". How you do arrive at "55 4E 41 4D 45 28 31 29", probably remains a mystery to all of us.

0
With reference to ur query,
int main()
{
char ch='a';
char*ptr=&ch;
clrscr();
printf("Converting character to hexadecimal format");
printf("%p",ptr);
getch();
return 0;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.