AVR Bitwise Operations
In C, ! is the logical negation operator: !x has the value 1 if x is falsy (i.e. zero), and the value 0 if x is truthy (i.e. non-zero). !!x has just two negations back-to-back, which gives the same logical truth value as x itself, but it collapses all true values to 1. (It's worth remembering that e.g. 2, 0x1000, and -123 are all true in C.)

(val &amp; (HIGH &lt;&lt; i))


This is just HIGH shifted left by i bits, and that value anded with val. i.e. if HIGH is 1, it picks the ith bit of val (counting from zero).

So, e.g. if i is 3, (val &amp; (1 &lt;&lt; i)) might be 0x08, and the following !! would collapse that to 1.