Shift Register on ATMEGA328p
This is what I expect for val = 1
PORTD |= (1 &lt;&lt; DATA)
As PORTD is the data pin on the shift register, it should get 00000001.

your deduction is correct and the code is correct -&gt; remember this is the case for LSBFIRST. so &quot;val = 0x01&quot; should be sent out as &quot;0b1000 0000&quot;, which is precisely what the code is doing.

!(val &amp; (HIGH &lt;&lt; 0))

the &quot;!!&quot; operator is often used to turn a logic value into either '1' or '0'.
the code for shiftout() can be greatly improved.