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

what is the output for this question: main() { int i=1; printf("%d%d%d",i,i++,++i); }

9 Answers  


How can I read a directory in a C program?

2 Answers   Bright Outdoor, Wipro,


What is the behavioral difference when include header file in double quotes (“”) and angular braces (<>)?

0 Answers  


Hai what is the different types of versions and their differences

0 Answers  


How can you return multiple values from a function?

0 Answers  






What is %d used for?

0 Answers  


what is the output for the code : main() { int i,j; printf("%d %d ",scanf("%d%d",&i,&j)); }

20 Answers   Infosys,


define function

4 Answers   Assurgent, Sonata,


what different between c and c++

1 Answers  


read an array and search an element

1 Answers  


what value is returned to operating system after program execution?

0 Answers  


Which is the memory area not included in C program? give the reason

0 Answers   IBM, TCS,


Categories