1] What would be the output of the following program?
main()
{
int i = 32,j = 0x20,k,l,m;
k = j | j;
l = i & j;
m = k ^ l;
printf("%d %d %d %d %d",i,j,k,l,m);
}
A] 32 32 32 32 0
B] 0 0 0 0 0
C] 0 32 32 32 32
D] 32 32 32 32 32
2] What would be the output of the following program?//65535
main()
{
unsigned int m = 32;
printf("%x",~m);
}
A] ffff
B] 0000
C] ffdf
D] ddfd
3] What would be the output of the following program?
main()
{
unsigned int a = 0xffff;
~a;
printf("%x",a);
}
A] ffff
B] 0000
C] 00ff
D] None of the above.
4] Point out the error in the following program.
main()
{
unsigned int a,b,c,d,e,f;
a = b = c = d = e = f = 32;
a <<= 2;
b >>= 2;
c ^= 2;
d |= 2;
e &= 2;
f ~= 2;
printf("\n %x %x %x %x %x %x",a,b,c,d,e,f);
}
5] To which numbering system can the binary number 1011011111000101 be easily converted to?
6] Which bitwise operator is suitable for checking whether a particular bit is 'on' or 'off'?
7] Which bitwise operator is suitable for turning of a particular bit in a number?
8] Which bitwise operator is suitable for putting on a particular bit in a number?
9] On left shifting, the bits from the left are rotated an brought to the right and accommodated where there is empty space on the right? < True / False >
10] Left shifthing a number by 1 is always equibalent to multiplying it by 2. < Yes / No >
11] Left shifting an unsigned int or char by 1 is always equivalent to multiplying it by 2. < Yes / No >
12] What would be the output of the following program?
main()
{
unsigned char i = 0x80;
printf("\n %d",i << 1);
}
A] 0
B] 256
C] 100
D] None of the above.
13] What is the following program doing?
main()
{
unsigned int m[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
unsinged char n,i;
scanf("%d",&n);
for(i = 0; i <= 7; i++)
{
if (n & m[i])
printf("\n yes");
}
}
14] What does the follwing program do?
main()
{
char *s;
s = fun(128,2);
printf("\n %s",s)
}
fun(unsigned int num,int base)
{
static char buff[33];
char *ptr;
ptr = &buff[ sizeof(buff) - 1];
*ptr = '\0';
do
{
*--ptr = "0123456789abcdef"[num % base];
num /= base;
}while (num != 0);
return ptr;
}
A] It converts a number to given base.
B] It gives a compilation error.
C] None of the above.
15] #define CHARSIZE 8
#define MASK(y) ( 1 << % CHARSIZE)
#define BITSLOT(y) (y / CHARSIZE)
#define SET(x,y) (x[BITSLOT(y) |= MASK(y))
#define TEST(x,y) (x[BITSLOT(y)] & MASK(y))
#define NUMSLOTS(n) ((n + CHARSIZE - 1) / CHARSIZE)
Given the above macros how would you
(a) declare an array arr of 50 bits.
(b) put the 20th bit on.
(c) test whether the 40th bit is 'on' or 'off'.
16] Consider the macros in problem 14.15 above. On similar lines can you define a macro which would clear a given bit in a bit array?
17] What does the following progaram do?
main()
{
unsigned int num;
int c = 0;
scanf("%u",&num);
for( ; num; num>>= 1)
{
if(num & 1)
c++;
}
printf("%d",c);
}
A] It counts the number of bits which are on in the number num.
B] It sets all bits in the number num to 1.
C] It sets all bits in the number num to 0.
D] None of the above.
18] What would be the output of the following program?
main()
{
printf("\n %x", -1 >> 4);
}
A] ffff
B] 0fff
C] 0000
D] fff0
19] In the statement expression1 >> expression2 if expressin1 is a signed integer with its leftmost bit set to 1 then on right-shifting it the result of the statement would vary from computer to computer. < True / False >
20] What does the following program do?
main()
{
unsigned int num;
int i;
scanf("%u",&num);
for( i = 0; i < 16; i++)
printf("%d",(num << 1 & 1 << 15)? 1: 0);
}
A] It prints all even bits from num.
B] It prints all odd bits from num.
C] It prints binary equivalent fo num.
D] None of the above.
***********************************************************************
****************** ANSWERS ******************
***********************************************************************
1] A
2] C
3] A
4] Error is in f~= 2, since there is no operator as '~='.
5] Hexadecimal, since each 4-digit binary represents one hexadecimal digit.
6] The '&' operator.
7] The '|' operator.
8] False.
10] No.
11] Yes.
12] B
13] B
14] A
15] char arr[NUMSLOTS(50)];
SET(arr,20);
if (TEST(arr,40))
16] #define CLEAR(x,y) (x[BITSLOT(y)] &= ~MASK(y))
17] A
18] A. On computers which don't support sign extension you may get B.
19] True.
20] C
No comments:
Post a Comment