Getting a binary string and convert it to decimal
What you want are the bit-shifting operators &lt;&lt; and >>, and the OR operator |:

for(int i = 0; i &lt; 4; i++) {
    Serial.println(digitalRead(5 + i));
    Dstate = Dstate | (digitalRead(5 + i) &lt;&lt; i);
}


You'll notice I changed the loop so it runs from 0 to 3 instead of 5 to 9 - it makes other parts easier if you start counting from 0.

Then the line:

Dstate = Dstate | (digitalRead(5 + i) &lt;&lt; i);


is where all the magic happens.  Let's break it down:

digitalRead(5 + i)


That of course gives you a 0 or 1 for pins 5, 6, 7 and 8 in turn.

&lt;&lt; i


That shifts the value returned by digitalRead() left i bits.  For instance, if digitalRead() returns 1 and i is 0 then 1 is left shifted 0 times so remains as 0b0001.  If i is 1 then it left shifts one bit, so the value becomes 0b0010.  If i is 2 then it shifts two bits, so you get 0b0100.

Finally the result is combined with the current value of Dstate with OR, so the four values basically get laid over the top of each other.

So say you have the four switches in the positions ON-OFF-ON-OFF and Dstate starts off as 0, then the sequence would be:

i = 0, digitalRead = 1, shifted = 0b0001, OR = 0b0001
i = 1, digitalRead = 0, shifted = 0b0000, OR = 0b0001
i = 2, digitalRead = 1, shifted = 0b0100, OR = 0b0101
i = 3, digitalRead = 0, shifted = 0b0000, OR = 0b0101