如何在64位寄存器字段中设置第45位? [英] How to set 45th bit in a 64 bit register field?
问题描述
我试图使用C在64位宽的寄存器中设置第46位,如何设置该位?
I was trying to set 46th bit in a register which of 64 bits wide using C.How do i go about setting this bit ?
目前我正在这样做:
uint32_t= address ;
uint64_t data =1ULL << 46;
打印此图像表明第14位正在设置.我无法将第32位设置为偶数.如果我将第32位设置为0,则设置了第0位.33将设置第1位.看起来它在0-之后进行循环移位31再一次从0开始.
Printing this is showing that bit 14 is getting set.I am not able to set even bit 32. If i set bit 32 it sets bit 0. 33 will set bit 1. Looks like it is doing circular shifting after 0-31 again it starts over with 0.
以64位宽注册.
任何想法我该如何设置该位?
Any idea how do i go about setting this bit ?
例如:
reg_addr.val = FEATURE_REG;
printf(stdout, "Programming enable at address %x=%llx\n",
reg_addr.val,reg_addr.val);
data.val = (1ULL << 46);
printf("Data value %llx\n",data.val);}
推荐答案
如果您将类型用作uint32_t或uint64_t,则可以正确打印:
If you use types as uint32_t or uint64_t printing correctly is done with:
printf(stdout, "Programming enable at address %" PRIu32 "=%" PRIu64 "\n",reg_addr.addr, reg_addr.val);
假设reg_addr.addr的类型为uint32_t,而reg_addr.val的类型为uint64_t.
assuming reg_addr.addr is of type uint32_t and type reg_addr.val is of uint64_t.
这篇关于如何在64位寄存器字段中设置第45位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!