[英]Representing N bit int as hex in c++
I've a number between 0 and 63, so max 6 bits. 我的数字在0到63之间,所以最多6位。
Then I've to represent this number in hexadecimal. 然后,我必须用十六进制表示该数字。
How can I force the reresentation of my number in 8 bits so that if I have: 如何强制以8位重新表示我的数字,以便在我有以下情况时:
int x = 60;
cout << std::hex << x;
it prints 0x3C
? 它打印
0x3C
吗?
try this : 尝试这个 :
#include<iostream>
#include <iomanip>
using namespace std;
}
int main(){
int x = 60;
cout<<showbase; // show the 0x prefix
cout<<hex<<x;
return 0;
}
output : 输出:
0x3c
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.