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 / 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 |
How many keywords are there in c?
What are preprocessor directives in c?
Are local variables initialized to zero by default in c?
When do we get logical errors?
What is void c?
Write a Program to find whether the given number or string is palindrome.
List at least 10 sorting methods indicating their average case complexity, worst case complexity and best case complexity.
Write a c program to enter a string of paragraph and replacing a particular word which is repeated in the paragraph by another word?
2 Answers ME, Synfusion, Wipro,
How to write a code for implementing my own printf() and scanf().... Please hep me in this... I need a guidance... Can you give an coding for c... Please also explain about the header files used other than #include<stdio.h>...
struct node { int *a; char *b; char array[12]; }; struct node m,*n; assign the value in *a,*b,char array[12]
how to write optimum code to divide a 50 digit number with a 25 digit number??
WHICH TYPE OF JOBS WE GET BY WRITING GROUPS .WHEN THE EXAMS CONDUCTED IS THIS EXAMS ARE CONDUCTED EVERY YEAR OR NOT.PLS TELL ME THE ANSWER