现在的位置: 首页 > 综合 > 正文

c++下使用CString将字符串转二进制、八进制、十进制、十六进制

2013年03月20日 ⁄ 综合 ⁄ 共 616字 ⁄ 字号 评论关闭

(1).转二进制

#include"afx.h"
#include<stdio.h>
void main()
{
char c[5]="0101";
CString cs=_T(c);
int last=_tcstol(c,NULL,2);//2表示二进制
printf("%d\n",last);//使用十进制输出结果为5
}

(2).转八进制

#include"afx.h"
#include<stdio.h>
void main()
{
char c[5]="0101";
CString cs=_T(c);
int last=_tcstol(c,NULL,8);//8表示8进制
printf("%d\n",last);//使用十进制输出结果为65
}

(3).转十进制

#include"afx.h"
#include<stdio.h>
void main()
{
char c[5]="0101";
CString cs=_T(c);
int last=_tcstol(c,NULL,10);//10表示10进制
printf("%d\n",last);//使用十进制输出结果为101
}

(4).转十六进制

#include"afx.h"
#include<stdio.h>
void main()
{
char c[5]="0101";
CString cs=_T(c);
int last=_tcstol(c,NULL,16);//16表示16进制
printf("%d\n",last);//使用十进制输出结果为257
}

抱歉!评论已关闭.