我得到十六进制数0x04030201,存储在一个充满零的数组的中间.我的代码必须以位为单位确定此数字的大小.
我需要以两种不同的方式实现这一点.我的第一种方法是使用这样的sizeof()函数:
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int num[] = {0,0,0x04030201,0,0};
cout<<"The size of the integer is "<<sizeof(num[2])*4<<" bits."<<endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我的预期输出是28位(7位有效字符的4位).但我的输出给出:
The size of the integer is 16 bits.
Run Code Online (Sandbox Code Playgroud)
我的错是什么?