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...

write a program to swap bits in a character and return the value
prototype of function
char fun (char a, charb flag c)
where fun returns a char, char a is a the value char b is
the bit to be changed and flag c is the bit value
for eg: x=fun(45,7,0)
since 45 is 0010 0101
and ow x should contain the value 65 (0110 0101)

Answer Posted / abdur rab

#include <stdio.h>

char fun ( char a, char b, int flag )
{
if ( flag ) return ( a |= ( flag << ( (int) b -
1 ) ) );
return ( a &= ~( 1 << ( (int) b - 1 ) ) );
}

int main ( int argc, char* argv [] )
{

char a = 45;

printf ( "\n Before change :%d", (int) a );
printf ( "\n After change :%d", (int) fun ( a,
(char) 7, 1 ) );

return ( 0 );
}

Is This Answer Correct ?    1 Yes 9 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

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

1290


What is a void pointer in c?

1158


How do I get a null pointer in my programs?

1164


What is array in c with example?

1356


what is a NULL Pointer? Whether it is same as an uninitialized pointer?

1326


What is scanf_s in c?

1169


Here is a neat trick for checking whether two strings are equal

1073


An instruction which is analysed and acted upon by the processor prior to the compiler going its work a) directive b) constructive c) constant d) absolute mode

1149


Define Spanning-Tree Protocol (STP)

1178


Why main is not a keyword in c?

1318


Is there a way to jump out of a function or functions?

1165


How does struct work in c?

1137


Explain what is gets() function?

1118


How reliable are floating-point comparisons?

1150


What is the modulus operator?

1258