L9: Bitfields, Unions, and Enums & Bitwise Operations

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/20

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

21 Terms

1
New cards

sizeof()

What command can tell us the size (in bytes) of any variable or type?

2
New cards
union my_union {
  int i;
  float f;
  char c;
} my_var;

Declare a union titled my_union containing an int, i, a float, f, and a char, c. The instance variable should be called my_var.

3
New cards

All internal elements overlap.

What is special about the way a union is stored in memory?

4
New cards
enum color {
  RED,
  GREEN,
  BLUE
};

Create an enum titled color with the members RED, GREEN and BLUE.

5
New cards

The order of bytes in a word or multibyte value

What is endianness?

6
New cards

Most significant byte first (lowest address)

How are bytes ordered in big-endian systems?

7
New cards

Least significant byte first (lowest address)

How are bytes ordered in big-endian systems?

8
New cards

12 34 56 78

How would the hexadecimal value 0x12 34 56 78 be stored in a big endian system?

9
New cards

78 56 34 12

How would the hexadecimal value 0x12 34 56 78 be stored in a little endian system?

10
New cards

It compares each bit of two numbers and returns 1 if both corresponding bits are 1, otherwise it returns 0.

What does the & (bitwise AND) operator do?

11
New cards

It compares each bit of two numbers and returns 1 if at least one of the corresponding bits is 1.

What does the | (bitwise OR) operator do?

12
New cards

It compares each bit of two numbers and returns 1 if the corresponding bits are different, otherwise it returns 0.

What does the ^ (bitwise XOR) operator do?

13
New cards

It inverts each bit of a number. All 1 bits become 0, and all 0 bits become 1

What does the ~ (bitwise NOT) operator do?

14
New cards

It shifts the bits of a number to the left by a specified number of positions. This effectively multiplies the number by 2 for each position shifted.

What does the << (bitwise left shift) operator do?

15
New cards

It shifts the bits of a number to the right by a specified number of positions. This effectively divides the number by 2 for each position shifted.

What does the >> (bitwise right shift) operator do?

16
New cards

0001

What is the result of 5 & 3 in binary?

17
New cards

0111

What is the result of 5 | 3 in binary?

18
New cards

0110

What is the result of 5 ^ 3 in binary?

19
New cards

0101

What is the result of ~5 in binary?

20
New cards

1010

What is the result of 5 << 1 in binary?

21
New cards

0010

What is the result of 5 >> 1 in binary?