get the number of a hexa characters

415 pts.
Tags:
C
Programming
I have the next structure:
 

typedef struct Test01 {
 
	 char def [10] ; 
	 char efg[4]; // holds an integer value in hexa representation 
	 char xyz [10];

 } test01_t 


int main ( int argc , char ** argv ) {


	test01_t tt01 ; 	
	memcpy ( tt01.def , "EFG" ,3 ) ; 
	memcpy ( tt01.xyz , "XYZ" ,3 ) ; 
	tt01.efg[0] = 0X0 ; 
	tt01.efg[1] = 0X0 ; 
	tt01.efg[2] = 0X04 ; 
	tt01.efg[3] = 0XB0 ; 

}
how can I obtain the 1200 integer value which is the equivalent to "0x0004B0" ? 
I know it is a dummy question, but I cannot get with sscanf, sprintf 
Thanks in advance.

Answer Wiki

Thanks. We'll let you know when a new response is added.

It’s a side element, but did it help make the purpose of cvthc() clear? I’d assume it did since you passed a correct length. It’s handy in the right cases, but not here. — Tom

Discuss This Question: 9  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta
    Your question history indicates something other than a simple academic question, so how do you want the values captured? Do you have a variable you want to store them in or do you have some other usage in mind? -- Tom
    125,585 pointsBadges:
    report
  • carlosdl
    The equivalent to "0x0004B0" could be obtained this way:

    char example[10] = "0x0004B0";
    strtol(efg,0,16);
    But assigning the individual chars as numbers the way you are doing it, does not produce the string you want to convert to decimal.

    In other words, 0x0 is a different thing than "0x0".
    70,220 pointsBadges:
    report
  • carlosdl
    The code should've been:

    char example[10] = "0x0004B0";
    strtol(example,0,16);

    70,220 pointsBadges:
    report
  • GraceP
    Thanks =) for all the answers. 
    Yes, I have ccsid in that value that comes included in some structure of the v6r1 iSeries. In debug mode I can see that the number 1200 is in hexadecimal ( 000004B0) but I cannot obtain the 1200. 

    The answer comes with my teammate that suggest me to use the cvthc API. I will try and let you know.

    Thanks 
    415 pointsBadges:
    report
  • GraceP
    Also I would try with the strtol function, thanks! 
    415 pointsBadges:
    report
  • TomLiotta
    The cvthc() and cvtch() APIs shouldn't be relevant to this. The strtol() function does type conversion, but the APIs do forms of character translations. The APIs won't give an integer result. -- Tom
    125,585 pointsBadges:
    report
  • GraceP
    Certainly  cvthc() and cvtch() APIs didn't return the numeric value, the strtol function works as I wanted. 
    Thanks
    415 pointsBadges:
    report
  • carlosdl
    Great to know, thanks for following up.
    70,220 pointsBadges:
    report
  • GraceP
    I used both functions, something like: 
    char * ptr = tt01.efg ; 
    cvthc(receiver, ptr, 8 );           
    long int ccsid = strtol (receiver, 0,16);  // 1200
    415 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following