What is the purpose of the code, and is there any problem
with it?

unsigned int f( unsigned n )

{ return –n & 7; }



What is the purpose of the code, and is there any problem with it? unsigned int f( unsigned n )..

Answer / senthil

f returns the 8's complement of the lower 3 bits of a given number

................................(2's complement of n)&0x07
f(0) => -00000000&00000111 => 00000000&00000111 => 00000000 (0)
f(1) => -00000001&00000111 => 11111111&00000111 => 00000111 (7)
f(2) => -00000010&00000111 => 11111110&00000111 => 00000110 (6)
f(3) => -00000011&00000111 => 11111101&00000111 => 00000101 (5)
f(4) => -00000100&00000111 => 11111100&00000111 => 00000100 (4)
f(5) => -00000101&00000111 => 11111011&00000111 => 00000011 (3)
f(6) => -00000110&00000111 => 11111010&00000111 => 00000010 (2)
f(7) => -00000111&00000111 => 11111001&00000111 => 00000001 (1)
f(8) => -00001000&00000111 => 11111000&00000111 => 00000000 (0)
f(9) => -00001001&00000111 => 11110111&00000111 => 00000111 (7)
f(10) => -00001010&00000111 => 11110110&00000111 => 00000110 (6)
.
.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

write a program to find the sum of the array elements in c language?

24 Answers   ICT, Infosys, Wipro,


Explain what is a stream?

0 Answers  


#include<stdio.h> main() {int i=1;j=1; for(;;) {if(i>5) break; else j+=1; printf("\n%d",j) i+=j; } }

7 Answers   HCL,


What is the basic structure of c?

0 Answers  


What is non linear data structure in c?

0 Answers  






Do you know the use of 'auto' keyword?

0 Answers  


A float occupies 4 bytes in memory. How many bits are used to store exponent part? since we can have up to 38 number for exponent so 2 ki power 6 6, 6 bits will be used. If 6 bits are used why do not we have up to 64 numbers in exponent?

0 Answers  


What is difference between structure and union with example?

0 Answers  


Are the variables argc and argv are always local to main?

0 Answers  


Write a code of a general series where the next element is the sum of last k terms.

0 Answers   Aspiring Minds,


what is the output of following question? void main() { int i=0,a[3]; a[i]=i++; printf("%d",a[i] }

3 Answers  


What is the value of y in the following code? x=7;y=0; if(x=6) y=7; else y=1;

12 Answers   TCS,


Categories