Originally Posted by
Laserve
what if you'd do (value & bit) != 0 ? isnt that either 0 or 1 ?
It would be the same.
Originally Posted by
jafet
But!! isn't!! double!! exclaimation!! so!! leet!! ??!!
No, it's a C idiom that I figured was not widely recognized, but I didn't know how much.
I first saw it about a decade or so ago, and I've come to read it as a "move bit to LSB" "operator". Mentally I picture it something like this:
Code:
0100:0000 -> 0000:0001, 0000:0000 -> 0000:0000
So upon inspection, I can more easily tell that this is doing what is expected like this:
Code:
#define UART_RX 0x40
const volatile unsigned char *UartStatus = (const volatile unsigned char *)0x38;
volatile unsigned char UartRxData;
/* interrupt */ void UartReceive(void)
{
UartRxData <<= 1; /* shift current value to make room for new LSB */
UartRxData |= !!(*UartStatus & UART_RX); /* add new bit in LSB */
}
than like this
Code:
#define UART_RX 0x40
const volatile unsigned char *UartStatus = (const volatile unsigned char *)0x38;
volatile unsigned char UartRxData;
/* interrupt */ void UartReceive(void)
{
UartRxData <<= 1; /* shift current value to make room for new LSB */
UartRxData |= (*UartStatus & UART_RX) != 0; /* add new bit in LSB */
}
or other variants. YMMV.
Related discussions:
Originally Posted by
manutd
Ah! Not the leet thing again!
Apparently the point of this thread is not what I thought.