#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    9
    Rep Power
    0

    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. #2
  3. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    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

IMN logo majestic logo threadwatch logo seochat tools logo