Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Binary Battelfild

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

What is the binary representation of 15?

a)

1110

b)

1111

c)

1010

d)

1101

2.

Which operator is used in C for the bitwise AND operation?

a)

&

b)

&&

c)

|

d)

^

3.

What is the output of `5 & 3` in C?

a)

1

b)

2

c)

3

d)

4

4.

In C , What does the '<<' operator do?

a)

Right - Shift

b)

Left - Shift

c)

Bitwise AND

d)

Bitwise OR

5.

Which bitwise operator in C can be used to toggle bits?

a)

&

b)

^

c)

|

d)

<<

6.

6. What is the output of `~5` in an 8-bit representation in C?

a)

1111 1010

b)

0000 0101

c)

1111 1100

d)

1010 1010

7.

7. What is the result of `5 | 3`?

a)

7

b)

5

c)

3

d)

8

8.

If `int x = 8`, what is the result of `x >> 1`?

a)

2

b)

4

c)

6

d)

7

9.

Which expression in C sets the 3rd bit from the right to

a)

`x | (1 << 2)`

b)

   `x & (1 << 2)`

c)

`x ^ (1 << 3)`

d)

 `x | (1 << 3)`

10.

which of the following checks if the 1st bit (from the right) of 'x' is set?

a)

'x & (1<<0)'

b)

'x | (1<<0)'

c)

'x>>1'

d)

'x<<1'

11.

What does 'x&=~(1<<n)' do in C ?

a)

Sets the nth bit to 1

b)

Sets the nth bit to 0

c)

Toggles the nth bit

d)

No operation

12.

How do you clear all bits in an integer 'x' in C ?

a)

'x & 0xFF'

b)

'x | 0x00'

c)

'x &= 0x00'

d)

'x = 0'

13.

Given 'int a = 5,b = 2; ' what is the value of 'a<<b' ?

a)

10

b)

20

c)

25

d)

40

14.

What is the output of 'printf("%d", 7 ^ 3); '?

a)

0

b)

3

c)

4

d)

8

15.

How many bits are required to represent the hexadecimal number '0xFF' in binary ?

a)

4

b)

8

c)

12

d)

16

16.

What is the value of '0x3F & 0x55' ?

a)

0x30

b)

0x05

c)

0x15

d)

0x35

17.

What does the expression `x ^= (1<<k)` do in C ?

a)

Sets the Kth bit

b)

Clears the kth bit

c)

Toggles the kth bit

d)

Sets all bits

18.

How do you check if a number is a power of 2 using a single expression ?

a)

`x == 2`

b)

`(x & (x-1)) == 0

c)

`x | 1`

d)

`x ^ 2`

19.

What is the binary representation of `0xA7` ?

a)

1010 0011

b)

1010 1111

c)

1010 0111

d)

1011 1001

20.

How do you isolate the lowest set bit in a binary number `x` ?

a)

`x & 0x01`

b)

`x & (-x)`

c)

`x >> 1`

d)

`x ^ x`

21.

What does `x | ( x-1)` do to the bits of `x` ?

a)

Sets all bits in x to 1

b)

Clears all bits

c)

Sets all bits lower than the lowest set bit of x

d)

Inverts x

22.

In C, `x &= (x-1);` has what effect on x ?

a)

Sets all bits in x to 0

b)

Clears the lowest set bit of x

c)

Toggles all bits of x

d)

Shifts bits in x left by 1

23.

Which of the following swaps two numbers without using a temporary variable ?

a)

`a = a + b; b= a - b; a= a-b;

b)

`a = a | b; b = a | b; a = a & b;`

c)

`a ^ = b; b ^= a; a ^= b;`

d)

`a &= b; b |=a; a ^= b;`

24.

What is the output of `printf("%d",15<<2);` ?

a)

30

b)

45

c)

60

d)

63

25.

Which expression in C will set only the least significant bit of `x` to 1 ?

a)

`x | 1`

b)

`x ^ 1`

c)

`x << 1`

d)

`x & 1`