inconsistent digital output on simple code
If I look at the first 5 lines:
byte b;
int out;
int D3 = 3;int D4 = 4;int D5 = 5;int D6 = 6;int D7 = 7;int D8 = 8;
void setup() {
  Serial.begin(9600);
  pinMode(out, OUTPUT);

You see that pinModeout, OUTPUT)uses a variableoutwhich is not initialized (it's only declared inint out`'.
I assume D3 to D8 are all output pins, so you have to replace the last line with:
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
pinMode(D5, OUTPUT);
pinMode(D6, OUTPUT);
pinMode(D7, OUTPUT);
pinMode(D8, OUTPUT);

Also, since you are using all pins in the same way, I suggest you use two variables: startPin and endPin. Then you can use a for loop to iterate through all pins. Also

always initialize variables.
use '0' instead of 48 when you convert from a byte value to a character (since you don't need to know the ASCII value of '0').

I don't have an Arduino compiler at hand, but it should look something like:
byte b = 0;
int out = 0;
const byte startPin = 3;
const byte endPin = 8;

void setup() {
  Serial.begin(9600);
  for (byte pin = startPin; pin &lt;= endPin; pin++)
  {
      pinMode(pin, OUTPUT);
      digitalWrite(pin, LOW);
  }
}

void loop() {
  while (Serial.available() == 0) {}
  b = Serial.read() - '0';
  out = b;
  Serial.print(&quot;\n Out is &quot;);
  Serial.println(out);
  digitalWrite(out, HIGH);
  delay(600);

  ...

However, from here you are using the pins as INPUT pins. You cannot change those on the fly, you might change them manually (by using pinMode(pin, INPUT)), but it does not seem normal to switch input and output pins, so maybe you should explain what you are intending with your application.