我使用cpuid操作码来检索处理器模型和扩展模型的值。我使用的文档说,我必须将扩展模型的值与模型的值连接起来,这样我就可以获得正确的模型。
Ex. Model: 2h
Model: Eh
Required Output: 2Eh这只是一个例子,但还有更多类似的例子。如何将这两个数字(它们是4位无符号整数)连接在一起,以便在C++中获得所需的输出?
发布于 2012-12-22 05:59:42
Shift和add:
exModel = 0x2;
model = 0xE;
output = (exModel << 4) + model;由于在上面的注释中提到了,你也可以使用联合,但我不推荐它-它使得代码非常不可移植(我认为这违反了严格的别名规则):
union myUnion
{
unsigned char output;
struct
{
unsigned char model : 4; // the order of these two fields
unsigned char exModel : 4; // is system dependent
};
};
union myUnion u;
u.exModel = 0x2;
u.model = 0xE;
output = u.output;发布于 2012-12-22 06:01:07
换档-好的。
联合-不是。
示例:
unsigned char ex_model = 0x2;
unsigned char model = 0xe;
unsigned int i = (ex_model << 4) | model;https://stackoverflow.com/questions/13997722
复制相似问题