We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
HI Friends,
I am using AT91SAM7SE512 controller, i have configured the input in port B.while compiling the program i am getting this warning.
main.c(8): warning: #61-D: integer operation result is out of range main.c(8): warning: #68-D: integer conversion resulted in a change of sign.
If anybody knows about this bug Please help me to rectify.
The code is
#define test (1<<31) //PB31
int main() { // Enable the clock of the PIOB for led and PIO for Switch
AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1 << AT91C_ID_PIOB) ; AT91F_PIO_CfgInput (AT91C_BASE_PIOB , test );
} with regards, Nanju...
Declare test as unsigned long:
#define test (1UL<<31)
Hi friend,
Thanks for your suggestion.
Now there is no warning.
May i know the reason for this declaration. #define test ((unsigned long)1<<31) //PB31
because i declared other pins like this "#define test (1<<20) //PB31".For that no warnings,only the warning is giving this PB31 pin.
Please advise.
with regards, Nanju..
A 32-bit integer has exactly what out sounds like - 32 bits. They are numbered from 0 to 31, and for an unsigned integer represents the values 2^0 (=1) to 2^31 (=2147483648).
For a signed integer, a system called two's complement is used. Half the capacity is used to store negative values, limiting the largest positive value to every bit but the last one, i.e. 2^0 + 2^1 + 2^2 + ... + 2^30 (=2147483647). A signed integer will the most significant bit set represents a negative value.
Your operation (1<<31) would convert the positive number 1 into a negative value by moving the bit all the way into the last position, and the compiler complained. Specifically saying that the digit 1 was unsigned, by the suffix u (1u) tells the compiler that the integer should not be treated as a signed integer and that the most significant bit is available to be used without generating a warning.
For more information about the two's complement format, see this link: en.wikipedia.org/.../Two's_complement
Thank you very much dear friend.