Bitwise Operators Flashcards
What is a bit?
The smallest unit of storage in a computer. It stores a 0 or a 1.
What is a byte?
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.
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.
byte
What is the smallest built-in data type?
char
How large is a char?
1 byte
Is it possible to access individual bits?
Yes, but not directly. Bitwise operators must be used to act at the bit level.
What is the most common standard for the way bits are arranged in memory?
2’s complement
Are all bitwise operations standardized across all machines?
No.
Some machines may not store all built-in data types in the same formats.
What is the Bitwise & (Bitwise AND) arity and what does it do?
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.
What is the Bitwise | (Bitwise OR [inclusive]) arity and what does it do?
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.
What is the Bitwise ^ (Bitwise exclusive OR) arity and what does it do?
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.
What is the Bitwise «_space;(left shift) arity and what does it do?
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.
What is the Bitwise»_space; (right shift) arity and what does it do?
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)
What is the Bitwise ~ (complement) arity and what does it do?
Arity: Unary
Description: Flips the bits in the operand. Similar to negation (all 1s become 0s, and all 0s become 1s)
What does x &= y mean?
x = x & y
(both x AND y)