|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Getting a String object containing hexadecimal representation of a char
hi,
the problem is i want to get hexadecimal representation of contents of a 'char' variable in String format. i.e. char ch = 127; its hexadecimal representation is '7F' How to get a string objet which have this hexadecimal representation? thanks in advance |
|
#2
|
||||
|
||||
|
Code:
#include<stdio.h>
int main(int argc, char **argv)
{
char x = 'A';
char y[5] = " ";
y[0] = x;
printf("value of y after copying x into it: %s\n",y);
snprintf(y,4,"%x",x);
printf("value of y after copying hex value of x into it: %s\n",y);
return 1;
}
output is: <oo7:Sun Jun 15> ./x value of y after copying x into it: A value of y after copying hex value of x into it: 41
__________________
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > Getting a String object containing hexadecimal representation of a char |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|