Hi,
Is there any library function available which will convert a passed hex string to its equivalent integer value???
Something like atoi() except that the input contains a hexadecimal string ("1A2" => 418).
TIA.
Hi,
Is there any library function available which will convert a passed hex string to its equivalent integer value???
Something like atoi() except that the input contains a hexadecimal string ("1A2" => 418).
TIA.
<Signature
name="Ruchikar"
quote="discussions are forgotten, only code remains"/>
I'm not sure how. Consider this code:Originally posted by Salem
sscanf
Code:int main() { char str[50]; char *hex_str = "1A2"; int int_output = 0; /* how to get the hex value of hex_str in int_output such that * int_output has the integer value * * using sscanf requires hex_str to be a hex integer pointer * sscanf( str, "%x", hex_str ); */ /* should print "int_output is: 418" */ printf( "int_output is: %d\n", int_output ); } /* end of main() */
<Signature
name="Ruchikar"
quote="discussions are forgotten, only code remains"/>
sscanf( hex_str, "%x", & int_output);
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Or you strtol() can be used, as:
Code:l_ret = strtol(o_str, (char **)NULL, 16); /* Where, 16 tells the base of the number system (obviously 16 for HEX) */
Last edited by shaik786; 10-16-2002 at 07:01 AM.