Redirected
392 views
2 votes
2 votes

Suppose int c = 0xdeadbeef, how many of the following statements clears the rightmost two bits in c and leaves the rest of the bits unchanged?
c = 0xdeadbeec
c &= 0xfffffffc
c = (c >> 2) << 2
c |= 0xfffffffc
c |= 0x00000003

2 Answers

1 votes
1 votes

Answer is 3

c = 0xdeadbeef

can be written as c = 11011110101011011011111011101111

1) c = 0xdeadbeec as c = c = 11011110101011011011111011101100 is true

2) c &= 0xfffffffc  as  c = 11011110101011011011111011101111&11111111111111111111111111111100 = 11011110101011011011111011101100 = 0xdeadbeec true

3) c = (c >> 2) << 2 now first right shift 2

so c becomes c = 11110111101010110110111110111011 again 2 left shit now c becomes 11011110101011011011111011101100 =0xdeadbeec true

4) c |= 0xfffffffc gives
c = 0xffffffff not true

5) c |= 0x00000003 gives

c = 0xdeadbeef not true

0 votes
0 votes
Only 1 and 2 statement will clear the two rightmost bits 0.

Related questions

0 votes
0 votes
2 answers
2
rajveer43 asked Jan 12
178 views
The number of full and half-adders required to add $32$-bit numbers is______________________
0 votes
0 votes
0 answers
3
Redcom1988 asked Dec 23, 2023
176 views
Design a counter according to the state diagram above using only NAND gates and JK Flip-flops (if needed) complete with state tables
0 votes
0 votes
0 answers
4