Bitwise Operators Flashcards

1
Q

What is a bit?

A

The smallest unit of storage in a computer. It stores a 0 or a 1.

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

What is a byte?

A

A bite is a unit of storage consisting of 8 bits, and is special because it is usually the smallest unit of /directly addressable/ storage.

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

What is the smallest storage unit that a variable can be made out of? Addresses in memory are also usually applied to this unit type.

A

byte

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

What is the smallest built-in data type?

A

char

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

How large is a char?

A

1 byte

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

Is it possible to access individual bits?

A

Yes, but not directly. Bitwise operators must be used to act at the bit level.

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

What is the most common standard for the way bits are arranged in memory?

A

2’s complement

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

Are all bitwise operations standardized across all machines?

A

No.

Some machines may not store all built-in data types in the same formats.

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

What is the Bitwise & (Bitwise AND) arity and what does it do?

A

Arity: Binary

Description: Similar to && operator, but on a bit-by-bit basis. Bits in the result are set to 1 if corresponding operand bits are both 1, and set to 0 otherwise.

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

What is the Bitwise | (Bitwise OR [inclusive]) arity and what does it do?

A

Arity: Binary

Description: Similar to the || operator, but on a bit-by-bit basis. Bits in the result set to 1 if at least one of the corresponding bits in the two operands is 1. 0 otherwise.

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

What is the Bitwise ^ (Bitwise exclusive OR) arity and what does it do?

A

Arity: Binary

Description: Bits in the result set to 1 if exactly one of the corresponding bits in the two operands is 1. Result bit set to 0 if both corresponding bits in operands are the same.

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

What is the Bitwise &laquo_space;(left shift) arity and what does it do?

A

Arity: Binary

Shifts the bits of the first operand to the left, by the number of bits specified in the second operand. Right fill with 0 bits.

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

What is the Bitwise&raquo_space; (right shift) arity and what does it do?

A

Arity: Binary

Description: Shifts the bits of the first operand to the right, by the number of bits specified in the second operand. Left fill depends on the machine. /Usually/ based on the sign (fill with 0s for positive numbers, 1s for negatives)

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

What is the Bitwise ~ (complement) arity and what does it do?

A

Arity: Unary

Description: Flips the bits in the operand. Similar to negation (all 1s become 0s, and all 0s become 1s)

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

What does x &= y mean?

A

x = x & y
(both x AND y)

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

What does x |= y mean?

A

x = x | y
(either or both)

17
Q

What does x ^= y mean?

A

x = x ^ y
(one or the other, but not both)

18
Q

What does x «= y mean?

A

x = x &laquo_space;y
(x shifted to the left by y bits)

19
Q

What does x&raquo_space;= y mean?

A

x = x&raquo_space; y
(x shifted to the right by y bits)