int型十进制转char[]型十六进制
char temp_buffer[ 200 ];
char pp;
pp = 99;
memset(( char * )temp_buffer, 0x00, sizeof( temp_buffer ));
sprintf( temp_buffer, "%02x/n", pp );
fprintf( stdout, "temp_buffer =%s/n", temp_buffer );
输出
temp_buffer=63
------------------------------------------------------------------
int型十六进制转int[]型十进制
char temp_buffer[ 200 ];
char pp;
pp = 99;
memset(( char * )temp_buffer, 0x00, sizeof( temp_buffer ));
sprintf( temp_buffer, "%02x/n", pp );
fprintf( stdout, "temp_buffer =%s/n", temp_buffer );
sscanf( temp_buffer, "%d", &i );
fprintf( stdout, "i =%d/n", i );
输出
i=63
-------------------------------------------------------
int型十六进制转int型十进制
char temp_buffer[ 200 ];
int pp;
pp = 63;
memset(( char * )temp_buffer, 0x00, sizeof( temp_buffer ));
sprintf( temp_buffer, "%02d/n", pp );
fprintf( stdout, "temp_buffer =%s/n", temp_buffer );
sscanf( temp_buffer, "%x", &i );
fprintf( stdout, "i =%d/n", i );
输出
i=99
---------------------------
char[] 到 int转换(函数)
十六进制->十进制
八进制->十进制
二进制->十进制
strtol函数
main()
{
char a[]=”1000000000”;
char b[]=”1000000000”;
char c[]=”ffff”;
printf(“a=%d/n”,strtol(a,NULL,10));
printf(“b=%d/n”,strtol(b,NULL,2));
printf(“c=%d/n”,strtol(c,NULL,16));
}
c语言中的进制转化
最新推荐文章于 2023-10-16 22:53:33 发布