我得意思是我接受一个串s="123",这个123本身就是16进制数据,可我现在要的是int d=123,怎么转换阿
我得意思是我接受一个串s="123",这个123本身就是16进制数据,可我现在要的是int d=123,怎么转换阿
atof, atoi, _atoi64, atol
Convert strings to double (atof), integer (atoi, _atoi64), or long (atol).
double atof( const char *string );
int atoi( const char *string );
__int64 _atoi64( const char *string );
long atol( const char *string );
Routine Required Header Compatibility
atof <math.h> and <stdlib.h> ANSI, Win 95, Win NT
atoi <stdlib.h> ANSI, Win 95, Win NT
_atoi64 <stdlib.h> Win 95, Win NT
atol <stdlib.h> ANSI, Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
#include <stdlib.h>
#include <stdio.h>
void main( void )
{
char *s; double x; int i; long l;
s = " -2309.12E-15"; /* Test of atof */
x = atof( s );
printf( "atof test: ASCII string: %s\tfloat: %e\n", s, x );
s = "7.8912654773d210"; /* Test of atof */
x = atof( s );
printf( "atof test: ASCII string: %s\tfloat: %e\n", s, x );
s = " -9885 pigs"; /* Test of atoi */
i = atoi( s );
printf( "atoi test: ASCII string: %s\t\tinteger: %d\n", s, i );
s = "98854 dollars"; /* Test of atol */
l = atol( s );
printf( "atol test: ASCII string: %s\t\tlong: %ld\n", s, l );
}
[此贴子已经被作者于2007-5-10 16:32:56编辑过]
这样说吧,s="123",int d=atoi(s),我想要的是d=0x123,atoi转换成的事10进制把
不能直接转么,我说的具体些吧。我从串口读取的数据,按照协议,这些数据是十六进制的,可我用的串口类进行数据接收的,只能一个字符一个字符的接受,所以,这些字符串本身就是16进制的,只不过接受时转换成了字符,我就是想在原样变回去。就是这样,不能直接变么?
比如:s="0010",d=0x0010,而不是d=0x00a
[此贴子已经被作者于2007-5-11 9:10:35编辑过]