OldSteve:
I decided to do a little test.
A'for' loopshift wins by 4 bytes of program space. Both use the same RAM.I commented out each method in turn:-
void setup()
{
// Common lines:-
Serial.begin(115200);
byte val = 16;
// 2124 program / 182 RAM:-
for (int i = 0; i < 8; i++)
{
bool b = val & 0x80;
Serial.print(b);
val = val << 1;
}
// or
// 2128 program / 182 RAM:-
for (int i = 7; i >= 0; i--)
{
bool b = bitRead(val, i);
Serial.print(b);
}
}
void loop(){}
Hello!
I'm new to arduino , I want to ask beginners questions ![]()
I don't understand below code, how it work?
bool b = val & 0x80;
- "&" mean Bitwise Operators?
- in case val=4...
(with"&0x80") val&0x80 = 00000100
(without"&0x80") val = 11111100
" &0x80 " how it work ?
Thanks ![]()