Operations Flashcards

1
Q

&&

A

Logical and

Returns true if both statements are true

eg x < 5 && x < 10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

||

A

Logical or

Returns true if (either) one of the statements is true

eg x < 5 || x < 4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

!

A

Logical not

Reverse the result, returns false if the result is true

!(x < 5 && x < 10)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

&

A

(bitwise AND)

The & operator compares each binary digit of two integers and returns a new integer, with a 1 wherever both numbers had a 1 and a 0 anywhere else

0, 0 –> 0
0, 1 –> 0
1, 0 –> 0
1, 1 –> 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

|

A

(bitwise OR)

the | operator is to the || operator as the & operator is to the && operator.

The | operator compares each binary digit across two integers and gives back a 1 if either of them are 1. Again, this is similar to the || operator with booleans.

0, 0 –> 0
0, 1 –> 1
1, 0 –> 1
1, 1 –> 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

~

A

(bitwise NOT)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
A

(bitwise XOR)

The ^ operator is similar to the & and | operators in that it takes an int or uint on both sides. When it is calculating the resulting number, it again compares the binary digits of these numbers. If one or the other is a 1, it will insert a 1 in to the result, otherwise it will insert a 0. This is where the name XOR, or “exclusive or” comes from.

0, 0 –> 0
0, 1 –> 1
1, 0 –> 1
1, 1 –> 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly