我使用以下代码检查位数25值是0还是1:
volatile unsigned int * regAddr;
unsigned int regval;
regAddress = (unsigned int *) 0xD2009010; //This is a valid address of register
regVal = *regAddress; //The return value here is 0xFE008000
if (!(regVal & 0x4000000)) //For the mentioned return value, I thought the condition will be different then 0 and so used '!' to convert the value
the bit is 0;
else
the bit is 1;
Run Code Online (Sandbox Code Playgroud)
此代码无法正常工作,我无法弄清楚原因.帮助任何人?提前致谢
获得第25位的可靠方法是:
if (!(regVal & (1 << 24) ))
Run Code Online (Sandbox Code Playgroud)
或者,如果您愿意:
#define BIT_25 (1 << 24) // the first-bit, shifted over 24 more times.
if (!(regVal & BIT_25 ))
Run Code Online (Sandbox Code Playgroud)
有些人提出"位数25"是不明确的,这取决于你是将0x01视为第一位还是第零位.
自己决定适合您的计划.
但无论如何,0x4000000都是对的.