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

(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
}

    原文作者:进制转换
    原文地址: https://blog.csdn.net/lengxin337/article/details/8850571
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞