Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

unsigned int f( unsigned n )

{ return –n & 7; }

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the difference between malloc() and calloc() function?

1046


Write a code to achieve inter processor communication (mutual exclusion implementation pseudo code)?

1119


What does typeof return in c?

1092


What is the advantage of c?

1125


How can I invoke another program (a standalone executable, or an operating system command) from within a c program?

1202


What are the different types of linkage exist in c?

1031


Why do we use pointer to pointer in c?

1082


There seem to be a few missing operators ..

1048


What is a macro, and explain how do you use it?

1077


What is optimization in c?

1000


What is gets() function?

1120


What is header file in c?

1068


Why ca not I do something like this?

1009


Dont ansi function prototypes render lint obsolete?

1124


The process of repeatedly running a set of computer instructions until some condition is specifed a) condition b) sequential condition c) global d) iteration

1098