for(byte i=0;i<8;i++)
{ data >>=1;
if(overflow) {
do blah;
}
}
A right shift cannot create an overflow condition. All you need to do is test the low order bit and shift the data afterwards.
for(byte i=0;i<8;i++)
{
if(data & 1) {
do blah;
}
data >>= 1;
}
If you need to test the high order bit first this code will work:
for(byte i=0;i<8;i++)
{
if(data & 0x80) {
do blah;
}
data <<= 1;
}
If data is a signed byte you can use (data < 0) instead of (data & 0x80).
Pete