WorksheetsBinary Battelfild
Total questions: 25
Worksheet time: 13mins
What is the binary representation of 15?
1110
1111
1010
1101
Which operator is used in C for the bitwise AND operation?
&
&&
|
^
What is the output of `5 & 3` in C?
1
2
3
4
In C , What does the '<<' operator do?
Right - Shift
Left - Shift
Bitwise AND
Bitwise OR
Which bitwise operator in C can be used to toggle bits?
&
^
|
<<
6. What is the output of `~5` in an 8-bit representation in C?
1111 1010
0000 0101
1111 1100
1010 1010
7. What is the result of `5 | 3`?
7
5
3
8
If `int x = 8`, what is the result of `x >> 1`?
2
4
6
7
Which expression in C sets the 3rd bit from the right to
`x | (1 << 2)`
`x & (1 << 2)`
`x ^ (1 << 3)`
`x | (1 << 3)`
which of the following checks if the 1st bit (from the right) of 'x' is set?
'x & (1<<0)'
'x | (1<<0)'
'x>>1'
'x<<1'
What does 'x&=~(1<<n)' do in C ?
Sets the nth bit to 1
Sets the nth bit to 0
Toggles the nth bit
No operation
How do you clear all bits in an integer 'x' in C ?
'x & 0xFF'
'x | 0x00'
'x &= 0x00'
'x = 0'
Given 'int a = 5,b = 2; ' what is the value of 'a<<b' ?
10
20
25
40
What is the output of 'printf("%d", 7 ^ 3); '?
0
3
4
8
How many bits are required to represent the hexadecimal number '0xFF' in binary ?
4
8
12
16
What is the value of '0x3F & 0x55' ?
0x30
0x05
0x15
0x35
What does the expression `x ^= (1<<k)` do in C ?
Sets the Kth bit
Clears the kth bit
Toggles the kth bit
Sets all bits
How do you check if a number is a power of 2 using a single expression ?
`x == 2`
`(x & (x-1)) == 0
`x | 1`
`x ^ 2`
What is the binary representation of `0xA7` ?
1010 0011
1010 1111
1010 0111
1011 1001
How do you isolate the lowest set bit in a binary number `x` ?
`x & 0x01`
`x & (-x)`
`x >> 1`
`x ^ x`
What does `x | ( x-1)` do to the bits of `x` ?
Sets all bits in x to 1
Clears all bits
Sets all bits lower than the lowest set bit of x
Inverts x
In C, `x &= (x-1);` has what effect on x ?
Sets all bits in x to 0
Clears the lowest set bit of x
Toggles all bits of x
Shifts bits in x left by 1
Which of the following swaps two numbers without using a temporary variable ?
`a = a + b; b= a - b; a= a-b;
`a = a | b; b = a | b; a = a & b;`
`a ^ = b; b ^= a; a ^= b;`
`a &= b; b |=a; a ^= b;`
What is the output of `printf("%d",15<<2);` ?
30
45
60
63
Which expression in C will set only the least significant bit of `x` to 1 ?
`x | 1`
`x ^ 1`
`x << 1`
`x & 1`
