AND Bitwise SPI question
hi guys!,
trying overcome awkward n00b-phase, have question bitwise magic came accros in sketch used read eeprom through spi bit banging. here piece of code:
if i'm right piece of code reads out byte bit bit starting msb , ending lsb. think understand code except line:
why line nessecary? can't 'bit' variable not used directly following if-statement?
i hope can give me explanation
cheers!
trying overcome awkward n00b-phase, have question bitwise magic came accros in sketch used read eeprom through spi bit banging. here piece of code:
code: [select]
int read_8(int address)
{
char bit;
char inbit;
char index;
int value = 0;
chip_select_low();
send_8(read);
send_address(address);
for(index = 0; index < 8; index++)
{
bit = digitalread(from_data_out);
inbit = bit & 0x01;
if(inbit == 1)
{
value = value + (0x80>>index);
sclk();
}
else
{
sclk();
}
}
chip_select_high();
return value;
}if i'm right piece of code reads out byte bit bit starting msb , ending lsb. think understand code except line:
code: [select]
inbit = bit & 0x01;why line nessecary? can't 'bit' variable not used directly following if-statement?
i hope can give me explanation

cheers!
quote
why line nessecary? can't 'bit' variable not used directly following if-statement?
digitalread return either high or low. high defined 1 , low defined zero. line "inbit = bit & 0x01;" make inbit indeed 1 or 0. since know bit either 1 or 0, isn't needed , use "bit" directly suggested.
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > AND Bitwise SPI question
arduino
Comments
Post a Comment