Begraphics:
But why bb != 255, what does this mean ? Is that a test? Or do you blind-test me so I am able to correct the code to bb >= 0 ?
When you defined the array as:
char ba[255];
byte bb;
ba[] is valid from ba[0] to ba[254].
if you try to use a for loop:
for(bb=254; bb > 0 ;bb--){}
this loop will not process offset 0, the first element in the array.
for(bb=254; bb > -1 ;bb--){}
// or
for(bb=254; bb >= 0 ;bb--){}
This for loop will never exit. a byte's range is 0 .. 255, when you decrement 0 you get 255. So, the test bb > -1 will always be true and bb >= 0 will also always be true.
so the only termination value is:
for(bb=254; bb != 255 ;bb--){}
The bb != 255 says: while bb not equal to 255 process the for loop.
If you want to process the array from 0 to 254 then:
for(bb=0; bb < 255 ;bb++){}
//or
for(bb=0; bb != 255 ;bb++){}
No tricks, the exclamation point character "!" is a logical NOT operator, don't confuse it with the BINARY NOT operator "~".
Logical operator work with TRUE, FALSE.
Binary operators work at the bit level:
byte b;
b = 1; // or B00000001
~b = 254; // or B11111110 This is read as 'not b'
b & b = 1; //
b & ~b = 0;
b | ~b = 255;
Chuck.