Document not found! Please try again

Bitwise Operators - sbdsi.saikat

121 downloads 2016 Views 487KB Size Report
Which bitwise operator is suitable for turning off a particular bit in a number? ... Assunming, integer is 2 byte, What will be the output of the program?
1

Bitwise Operators General Questions 1. In which numbering system can the binary number 1011011111000101 be easily converted to? A.Decimal system B. Hexadecimal system C. Octal system D.No need to convert Answer & Explanation Answer: Option B Explanation: Hexadecimal system is better, because each 4-digit binary represents one Hexadecimal digit.

2. Which bitwise operator is suitable for turning off a particular bit in a number? A.&& operator B. & operator C. || operator D.! operator Answer & Explanation Answer: Option B

3. Which bitwise operator is suitable for turning on a particular bit in a number? A.&& operator B. & operator C. || operator D.| operator Answer & Explanation Answer: Option D

4. Which bitwise operator is suitable for checking whether a particular bit is on or off? A.&& operator B. & operator C. || operator D.! operator Answer & Explanation Answer: Option B

Find Output of Program 1. Assunming, integer is 2 byte, What will be the output of the program? #include int main() { printf("%x\n", -1>>1);

Saikat Banerjee

2 return 0; }

A.ffff C. 0000 Answer & Explanation

B. 0fff D.fff0

Answer: Option A Explanation: Negative numbers are treated with 2's complement method. 1's complement: Inverting the bits ( all 1s to 0s and all 0s to 1s) 2's complement: Adding 1 to the result of 1's complement. Binary of 1(2byte) : 0000 0000 0000 0001 Representing -1: 1s complement of 1(2byte) : 1111 1111 1111 1110 Adding 1 to 1's comp. result : 1111 1111 1111 1111 Right shift 1bit(-1>>1): 1111 1111 1111 1111 (carry out 1) Hexadecimal : f f f f (Filled with 1s in the left side in the above step)

Note: 1. Fill with 1s in the left side for right shift for negative numbers. 2. Fill with 0s in the right side for left shift for negative numbers. 3. Fill with 0s in the left side for right shift for positive numbers. 4. Fill with 0s in the right side for left shift for positive numbers.

2. If an unsigned int is 2 bytes wide then, What will be the output of the program ? #include int main() { unsigned int m = 32; printf("%x\n", ~m); return 0; }

A.ffff C. ffdf Answer & Explanation

B. 0000 D.ddfd

Answer: Option C

3. Assuming a integer 2-bytes, What will be the output of the program? #include int main() { printf("%x\n", -1