XBee Newbie needs help getting started

ipsolutions:
Is this better?

if (Serial.available() >= 3) {

for (int x = 0; x < 4; x++){
                myNumber.B[x] = Serial.read();

The risk there is that if for some unforeseen reason, more than four bytes were received, the index (x) would overrun the array. This can cause all sorts of funny behavior and it can be difficult to track down.

The example below avoids that problem by waiting for exactly four bytes to be received. Of course this can create a different problem, if one byte gets lost somehow, the loop will just wait. Either approach might work as long as everything goes as planned, but I would sure avoid a possible out-of-bounds array index. It's not trivial to make these things bulletproof, it takes a little thinking. A start delimiter would be useful to mark the start of the number. Because the number is sent in binary, though, there is the question of what to use for a delimiter since theoretically any value could occur in one of the four bytes that represent the number. So now we are into escape sequences etc.

    int x = 0;
    while (x < 4) {
        if (Serial.available()) myNumber.B[x++] = Serial.read();
    }