C++ 如何用cout输出hex,oct,dec的解决方法
更新时间:2020年4月25日 17:45 点击:1670
HEX:
#include <iostream.h>
#include <iomanip.H>
main(void)
{
long n = 10000;
cout << hex << n ;
return 0;
}
OCT:
#include <iostream.h>
#include <iomanip.H>
main(void)
{
long n = 10000;
cout << oct << n ;
return 0;
}
DEC:
#include <iostream.h>
#include <iomanip.H>
main(void)
{
long n = 10000;
cout << dec << n << endl;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
cout.setf(ios::hex, ios::basefield);
cout << 100; // this displays 64
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
cout << "Enter a decimal number: ";
cin >> n;
cout << n << " in hexadecimal is: "
<< hex << n << '/n'
<< dec << n << " in octal is: "
<< oct << n << '/n'
<< setbase( 10 ) << n << " in decimal is: "
<< n << endl;
return 0;
}
复制代码 代码如下:
#include <iostream.h>
#include <iomanip.H>
main(void)
{
long n = 10000;
cout << hex << n ;
return 0;
}
OCT:
复制代码 代码如下:
#include <iostream.h>
#include <iomanip.H>
main(void)
{
long n = 10000;
cout << oct << n ;
return 0;
}
DEC:
复制代码 代码如下:
#include <iostream.h>
#include <iomanip.H>
main(void)
{
long n = 10000;
cout << dec << n << endl;
return 0;
}
复制代码 代码如下:
#include <iostream>
using namespace std;
int main()
{
cout.setf(ios::hex, ios::basefield);
cout << 100; // this displays 64
return 0;
}
复制代码 代码如下:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
cout << "Enter a decimal number: ";
cin >> n;
cout << n << " in hexadecimal is: "
<< hex << n << '/n'
<< dec << n << " in octal is: "
<< oct << n << '/n'
<< setbase( 10 ) << n << " in decimal is: "
<< n << endl;
return 0;
}
相关文章
- 这篇文章主要介绍了PHP实现将颜色hex值转换成rgb的方法,涉及PHP针对字符串与数组的数学运算相关操作技巧,需要的朋友可以参考下...2016-05-05
- 这篇文章主要介绍了C# wpf Brush转Hex字符串的实例代码,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-01-15
- php中有 bin2hex方法,但没有 hex2bin方法,以下简单实现 hex2bin : <?php function hex2bin($data) { $len = strlen($data); return pack("H" . $len...2016-11-25
- 本篇文章是对C++中如何用cout输出hex,oct,dec的方法进行了详细的分析介绍,需要的朋友参考下...2020-04-25
Android开发MediaCodec和lamemp3多段音频截取拼接
这篇文章主要为大家介绍了Android开发使用MediaCodec和lamemp3实现多段音频截取拼接的编程示例,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪...2022-04-27