#include
#include
using namespace std;
bitset<32> GetBitSet(int num)
{
bitset<32> bs(num);
return bs;
}
char *Get16string(int num)
{
char *buffer = new char[11];
char *bufferAddr = buffer;
buffer[0] = '0';
buffer[1] = 'x';
buffer[10] = '\0';
buffer = buffer + 2;
for(int i = 0; i < 8; i++)
{
buffer[i] = (char)(num << 4*i >> 28);
if((buffer[i] & (1 << 7)) != 0)
buffer[i] = buffer[i] + 16;
if(buffer[i] < 10)
buffer[i] += 48;
else
buffer[i] += 55;
}
return bufferAddr;
}
int main()
{
int num = 456789;
bitset<32> bs;
bs = GetBitSet(num);
char *num16String = Get16string(num);
cout<
return 0;
}
阅读(1350) | 评论(0) | 转发(0) |