
C++进制转换、字符串转数字
using namespace std;
发布日期:2021-05-10 01:23:26
浏览次数:11
分类:精选文章
本文共 1995 字,大约阅读时间需要 6 分钟。
������
���C++������������������������������������������������������������������C++���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
���������������������������������C++������������������������������ ```cpp #includeint main() {
int decNum = 255; // ���������������// ��������������������� bitset<32> binary(decNum); cout << binary << endl; // ���������������00000000000000000000000011111111 // ��������������������������������� stringstream ss; string hexStr; ss << hex << decNum << endl; hexStr = ss.str(); // ���������������ff // ��������������������� cout << binary.to_ulong() << endl; // ���������������255 // ��������������������������������� string binStr = "11111111"; // ������������������ ss << hex << stoi(binStr, nullptr, 2) << endl; hexStr = ss.str(); // ���������������ff // ��������������������������������� bitset<32> binaryStr(hexStr, 16); cout << binaryStr << endl; // ���������������00000000000000000000000011111111 // ��������������������������������� // ������������������������ stoi ��������� int decimal = stoi(hexStr, nullptr, 16); cout << decimal << endl; // ���������������255 // ������������������ stringstream stringstream ss2; ss2 << hex << hexStr; int decimal2; ss2 >> decimal2; cout << decimal2 << endl; // ��������������������������� string str = "1111"; // ������������������ bitset<32> binaryStr(str); cout << binaryStr << endl; // ��������������������������� cout << binaryStr.to_string() << endl;
}
������
������������������������������������������������������������������C++������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
哈哈,博客排版真的漂亮呢~
[***.90.31.176]2025年04月26日 20时58分41秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
[源码分析] 消息队列 Kombu 之 mailbox
2021-05-09
抉择之苦
2021-05-09
wx.NET CLI wrapper for wxWidgets
2021-05-09
微软网络数据包分析工具 Microsoft Network Monitor 3.2
2021-05-09
ASP.NET MVC Action Filters
2021-05-09
兰州大学百年校庆--风雨百年萃英路
2021-05-09
Eucalyptus企业云计算
2021-05-09
Service Broker 无法工作的问题修复
2021-05-09
Windows Server 2008 R2 Server Core
2021-05-09
WCF WebHttp Services in .NET 4
2021-05-09
ASP.NET MVC的Action Filter
2021-05-09
Powershell中禁止执行脚本解决办法
2021-05-09
HTTP协议状态码详解(HTTP Status Code)
2021-05-09
SQL Server Performance Dashboard Reports
2021-05-09
.Net 跨平台可移植类库PCL可用于任何平台包括Mono
2021-05-09
多种坐标系之间的转换 Proj.NET和DotSpatial
2021-05-09
资深人士剖析微软开源.NET事件:战略重心已经从PC转移到云端
2021-05-09