Comparing byte overlap? Say 00000001 vs 10000001

I have an usual, or maybe not question

Say I have two types:

00000001
10000001

The only overlap is the most right bit being “1” Is there a way to detect this or compare?

Just logical AND them together.
a = 00000001
b = 10000001

c = 00000001 Logical AND

c = a & b;

The logical AND will have a one wherever both bits bits were set in the inputs.

Pete

el_supremo:
Just logical AND them together.
a = 00000001
b = 10000001

c = 00000001 Logical AND

c = a & b;

The logical AND will have a one wherever both bits bits were set in the inputs.

Pete

I think you mean "bitwise AND".

"Logical AND" means something else.

	int n1 = 15; // the binary is 00001111      
	int n2 = 22; // the binary is 00010110
	
	// calculate bitwise AND
	int r1 = n1 & n2; // binary:  00000110 (decimal 6)

	// calculate logical AND	
	int r2 = n1 && n2; // (nonzero) && (nonzero) is always 1

There is a test here: TGg20P - Online C++0x Compiler & Debugging Tool - Ideone.com You can change the numbers as you please.

You are indeed correct. I perpetrated a terminological inexactitude.
Bitwise it is.

Thanks.
Pete

el_supremo:
I perpetrated a terminological inexactitude.

That's a bit of a mouthful (Sorry, could not resist)

...R