Hi there, first timer here, so please go easy...
Below are a couple of quick snippets of code, the first two work as I expect, the last doesn't for some reason. I'm completely new to the Arduino platform, but not to programming small micro's. I usually write in assembly, and much prefer using hex notation, but decided to get into C and thought this might be a good place to get my feet wet.
Here's the code:
//this works as expected
void setup()
{
Serial.begin(9600);
}
void loop()
{
byte tmp = B10000000;
tmp &= 0x7F;
Serial.println (tmp, HEX);
}
//this also works as expected
void setup()
{
Serial.begin(9600);
}
void loop()
{
int tmp = 128;
tmp &= 0x7F;
Serial.println (tmp, HEX);
}
//this does not work as expected
void setup()
{
Serial.begin(9600);
}
void loop()
{
byte tmp = 0x10;
tmp &= 0x7F;
Serial.println (tmp, HEX);
}
Anyone care to explain the behaviour I'm seeing here?
TIA