Combine bits from two ports into a single byte
Assuming PORTB and PORTD are correctly giving unsigned char values:

result = (PORTB &lt;&lt; 3) | (PORTD&gt;&gt;5)


would do it.

As a macro:  

#define SCSIBITS ((PORTB &lt;&lt; 3) | (PORTD&gt;&gt;5))


Then use like this:  

result = SCSIBITS


To make it clearer which specific bits are being used, write:  

#define SCSIBITS (((PORTB &amp; B00011111) &lt;&lt; 3) | ((PORTD &amp; B11100000) &gt;&gt; 5)))


It should be easier to see that the lower 5 bits of PORTB, and the upper 3 bits of PORTD are being used.

In the general case, where the values being manipulated are not unsigned char (should not be a problem in this specific case, but may be helpful to know), you might write:  

#define SCSIBITS ((unsigned char)((PORTB &amp; B00011111) &lt;&lt; 3) | ((PORTD &amp; B11100000) &gt;&gt; 5)))


or:  

#define SCSIBITS ((((unsigned char)PORTB &amp; B00011111) &lt;&lt; 3) | (((unsigned char)PORTD &amp; B11100000) &gt;&gt; 5)))


Here are a few links to bit-manipulation tutorials:
https://www.hackerearth.com/notes/bit-manipulation/
http://www.cprogramming.com/tutorial/bitwise_operators.html
http://www.tutorialspoint.com/ansi_c/c_bits_manipulation.htm