# Boolean Conditions?

#1

Are the operators “|” and “&”, and this chapter’s content in general similar to boolean conditions?

Like if all conditions are true (AND), or just one of the conditions are true (OR).

Logical-AND:

Logical-OR:

Are the Bitwise-OR, Bitwise AND, Exclusive-OR, Complement and Left/Right-shift used to find similarities?
I am having a trouble understanding how I can find similarities to a phone number, etc, by “Bitwise-ORing” a text or sentence…

#2

Recognising patterns in text can easily be done with deterministic state machines, given that phone numbers usually have well defined structures.

You can use the exclusive-or operator (xor) to test for equality of primitive types:

``````long A = 16, B = 16;
...
if (!(A^B))
{
// A == B
}
else
{
// A != B
}``````

But you might just as well use the regular == operator for this.

If you are looking for a given phone number in a piece of text, you can try finding its occurrence by xoring the corresponding bytes and shifting until you find or run out of text. (There are a few things you have to consider though. For example: 8788 5788 vs 87 88 57 88 )

#3

Thanks for the reply, I understand it better now.