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

When can a far pointer be used?

584


a function gets called when the function name is followed by a a) semicolon (;) b) period(.) c) ! d) none of the above

864


please give me a VIRTUSA sample palcement papers.... you will only send TECHNICAL SECTION..... that is help for me Advance Thanks........................

1535


What are global variables?

640


What are the applications of c language?

621






What are structure members?

590


code for quick sort?

1618


What is the difference between test design and test case design?

1564


How can I get back to the interactive keyboard if stdin is redirected?

663


Explain the concept and use of type void.

623


Are local variables initialized to zero by default in c?

545


What is the difference between functions abs() and fabs()?

643


can we have joblib in a proc ?

1650


What is a method in c?

622


What is the difference between far and near ?

678