转换十六进制到十进制

编程入门 行业动态 更新时间:2024-10-26 04:19:34
本文介绍了转换十六进制到十进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在寻找一种方法来转换(十六进制) (十六进制)到月 (十进制)容易。我发现了一个简单的方法来做到这一点,如:

INT K = 0x265; COUT<< K<< ENDL;

但随着我不能输入 265 。有反正它的工作这样的:

输入: 265

输出: 613

反正有做到这一点?

注意:我已经试过:

INT K = 0X,B; CIN>> B: COUT<< K + B<< ENDL;

和这是行不通的。

解决方案

的#include<的iostream> #包括<了iomanip> 诠释的main() {     INT X,Y;     性病:: stringstream的流;     给std :: cin>> X;     流<< X;     流>>性病::十六进制>> ÿ;     性病::法院<< ÿ;     返回0; }

I'm looking for a way to convert hex(hexadecimal) to dec(decimal) easily. I found an easy way to do this like :

int k = 0x265; cout << k << endl;

But with that I can't input 265. Is there anyway for it to work like that:

Input: 265

Output: 613

Is there anyway to do that ?

Note: I've tried:

int k = 0x, b; cin >> b; cout << k + b << endl;

and it doesn't work.

解决方案

#include <iostream> #include <iomanip> int main() { int x, y; std::stringstream stream; std::cin >> x; stream << x; stream >> std::hex >> y; std::cout << y; return 0; }

更多推荐

转换十六进制到十进制

本文发布于:2023-11-08 13:29:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569499.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:十六进制到十进制

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!