Cpp - bit manipulation Flashcards

1
Q

What is the smallest addressable unit of memory

A

A byte

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

How many bits in a byte

A

8

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

How to define a set of bit flags?

A

include

std::bitset<8> mybitset {};

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

What does test() do

A

Query whether a bit is a 0 or 1

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

what does set() do

A

Turn a bit on

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

reset()

A

turn a bit off

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

flip()

A

flip a bit value to its opposite

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

What are the following bitwise operator

<<
>>
~
&
|
^
A
left shift 
right shift
bitwise NOT
bitwise AND
bitwise OR
bitwise XOR
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does std::cout do to &laquo_space;and&raquo_space;

A

it overloads it so it performances a console output rather than a shift

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

Whats a bit mask

A

A predefined set of bits that is used to select which bits will be modified by subsequent operations

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

How to define bit masks

A

include

constexpr std::uint8_t mask{ 0b0000’0001 }; represents bit 0

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

test to see if bit is on or off

A

take the flags and bitwise AND it with the mask

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

setting a bit

A

take the flag and bitwise OR assignment it to the mask

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

Reset a bit

A

Take the flags then bitwise AND assignment it to the NOT of the mask

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