打印
[实用程序源码及工具软件]

C++语言下的int2hex()和hex2int()

[复制链接]
186|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
hotpower|  楼主 | 2023-9-18 22:17 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#pragma once
#include <iostream>
#include <iomanip> //std::hex, std::setw, std::setfill

template <class T>T hex2int(string hexstr);
template <class T>string int2hex(T val, int size);

template <class T>
T hex2int(string hexstr) {
        istringstream intstream(hexstr);
        T val;
        intstream >> hex >> val;
        return val;
}

template <class T>
string int2hex(T val, int size) {
        ostringstream hexstream;
        hexstream << hex << setw(size) << setfill('0') << setiosflags(ios::uppercase) << val;
        return hexstream.str();
}


使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:[url=http://www.21ic.com/tools/HotWC3_V1.23.html]

1460

主题

21619

帖子

506

粉丝