Bit Manipulation Flashcards

1
Q

what is a bit?

A

it’s either 1 or 0

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

what are the bitwise operators?

A
AND &
OR |
XOR ^
NOT ~
LEFT SHIFT <<
RIGHT SHIFT >>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

why do we use bit manipulation?

A

if we want to cram alot of info into one place to improve an algorithm efficiency

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

AND &

A

only true if both bits are true
1 & 1 = 1
0 & 1 = 0

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

OR |

A

true if any bit is true
1 & 1 = 1
0 & 1 = 1

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

XOR ^

A

true if only one bit is true
0 & 1 = 1
1 & 1 = 0

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

NOT ~

A

one’s complement operator
flips the input bit
~1 = 0
~0 = 1

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

LEFT SHIFT <

A

Shift the binary digits by n, pad 0’s on the right
each shift is a multiply by 2 unless there is an overflow
00010110
«
00000010 it’s in the second column so it will be shifted by 2 columns
01011000

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

what happens when u left shift out of 8 bits?

A

some processors throw it away or they wrap around which is called rotation

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

RIGHT SHIFT&raquo_space;

A

shift binary digits by n, pad 0’s on the left

each shift is a divide by 2 with round towards negative infinity

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