Problem with using hex

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

0b10000000 == 128 == 0x80 != 0x10

Anyone care to explain the behaviour I'm seeing here?

We don't know what the codes actually do. We don't know what you expect them to do. How can we explain why the code doesn't do what you expect?

PieterP:
0b10000000 == 128 == 0x80 != 0x10

Spot on sir...I'm a dummy :>)

I don't think I have had enough coffee this morning. I was attempting to set a bit mask in another piece of code earlier, when it didn't go as planned, I broke it down to being something wrong with the byte declaration. I just couldn't see the wood for the trees!

Thanks everyone, I'll go away now and smack my forehead for wasting your time :>)