用那些函数可以将一个数进行十进制、二进制、十六进制的相互转换? xie xie! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以把数转换成字符串然后再通过atof, atoi, _atoi64, atolConvert 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 );Example/* ATOF.C: This program shows how numbers stored * as strings can be converted to numeric values * using the atof, atoi, and atol functions. */#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 );}Outputatof test: ASCII string: -2309.12E-15 float: -2.309120e-012atof test: ASCII string: 7.8912654773d210 float: 7.891265e+210atoi test: ASCII string: -9885 pigs integer: -9885atol test: ASCII string: 98854 dollars long: 98854 用sprintf函数。int x=20 ;sprintf(str,"%d",x) ; //转10进制sprintf(str,"%X",x) ; //转16进制sprintf(str,"%O",x) ; //转8进制不能转二制 请问需要重新映射么? CString 内存泄露的问题,高手请进! 项目外包 高薪找人作个游戏外挂 MFC_对话框_类 的 删除 操作系统的复制文件进度对话框那个AVI动画不知道在系统里面哪里可以得到? 在 SDI中的MainFrame中如何得到当前View的句柄! 100分高难度问题:activeX如何控制在一台pc上只登陆一个实例? 想做一个文件夹同步的小程序,从哪里入手? 线程池是什么东东? 模拟点击鼠标 我的图不见了,请教大虾 急!菜鸟求救:我在vc++中找不到添加button的控件,怎么办?谢谢!
然后再通过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 );Example/* ATOF.C: This program shows how numbers stored
* as strings can be converted to numeric values
* using the atof, atoi, and atol functions.
*/#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 );
}
Outputatof test: ASCII string: -2309.12E-15 float: -2.309120e-012
atof test: ASCII string: 7.8912654773d210 float: 7.891265e+210
atoi test: ASCII string: -9885 pigs integer: -9885
atol test: ASCII string: 98854 dollars long: 98854
int x=20 ;
sprintf(str,"%d",x) ; //转10进制
sprintf(str,"%X",x) ; //转16进制
sprintf(str,"%O",x) ; //转8进制
不能转二制