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
What are the types of operators in c?
Explain c preprocessor?
Should I use symbolic names like true and false for boolean constants, or plain 1 and 0?
Why c is called a mid level programming language?
Explain how do you list files in a directory?
What does %2f mean in c?
What does %p mean?
Do you know the difference between exit() and _exit() function in c?
What is break in c?
What is main () in c?
What is a newline escape sequence?
What is the auto keyword good for?
What is file in c preprocessor?
Do pointers need to be initialized?
What is difference between structure and union in c programming?