So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By cgiles
#79875 Hello,

I'm tinkering with some code, looking how it works in libraries, it is a library for dmx, the light communication protocol, a serial communication, over rs 485 connection.

I often see this kind of code :

Code: Select allif ((U0IS & (1 << UIBD)))


U0IS is the interrupter status, and UIBD a kind of interrupter.

I don't understand why the 1 is at left the variable at right, can someone explains me why ?

Thanks, and happy new year :)
User avatar
By Pablo2048
#79910 Hi,
it depends on how the bits of the status register are described - if they are described in form of mask (for example
Code: Select all#define UIBO 0x08
) you can do direct check
Code: Select allU0IS & UIBO
, but if they are described as bit numbers (for example
Code: Select all#define UIBO 3
) you have to build bit mask by your own so there is this
Code: Select all(1 << UIBO)
. This math is done only once at compile time because the compiler optimize constants math expressions.