Enums and bitwise operators Flashcards
1
Q
How to declare an enum?
A
enum tag { INT, DOUBLE]
2
Q
How do you initialize an enum?
A
enum tag { A = 1, B = 2, C, D = -6, F } // Not really initializing
Each of the elements are assigned numbers in increasing order.
By default, the first element will be given 0.
enum tag newtag = A; // initializing
3
Q
How do you print out an enum?
A
enum tag newtag = INT
printf(“%d”, t); // prints out the number associated with that enum
4
Q
What should you watch out for when naming or tagging a struct, union or enums.
A
Structs, unions and enums share the same namespace so their names can collide.
5
Q
Where would you use enums inside a struct?
A
Enums can be used to as a tag to for a struct with a union.
6
Q
- w1 & w2
- w1 | w2
A
- Bitwise and - mask one value with another
- Bitwise or - merge together 2 values
7
Q
- w1 ^ w2
- ¬ (tilde) w
A
- bitwise exclusive or between 2 values
- ones complement invert
8
Q
- w &= 0xff
- b |= w & 0xff
A
- Need to check
- Merge b with the last byte of x ( need to check if it is supposed to be 0xff or something else )