Bit Manipulation Flashcards

1
Q

How do you perform addition

1101 + 1010

A

Answer: 1111

Explanation:
1+ 0 /0 +1 = 1
0+0 = 0
1+1 = 0 with 1 as carry

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

How do you perform subtraction

1101 + 1010

A

Answer: 0011

Explanation:
0-1 . In this case you need to borrow 1 from the 1 at position 2 thus making it 0 and making the value at position 1 as 2 and 2-1 =1

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

What is 1101 &laquo_space;2

A

0111 . you add 1’s when you move bits

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

What happens when you do XOR of two numbers?

A

only when both bits are not equal 1 is returned

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

What is 2’s complement?

A

flip the bits of a number and add 1 to it

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

How do you perform Multiplication?

A

1101 * 0100.

1101 * 0, 11010, 11011, 1101*0 and add all of them

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

How do you get the i th bit?

A

use mask =1 &laquo_space;i. Shift the value 00000001 to the left by i bits so the 1 bit will be at i position.
then you can do num & mask. This will ensure you only get the bit at i position

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

How do you set the i th bit?

A

use mask = 1 &laquo_space;i. Shift the value 00000001 to the left by i bits so the 1 bit will be at i position.
then you can do num | mask. This will ensure you only set the bit at i position

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