ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
how to exchnage bits in a byte
b7<-->b0 b6<-->b1 b5<-->b2 b4<-->b3
please mail me the code if any one know to 
rajeshmb4u@gmail.com
 Question Submitted By :: Rajesh
I also faced this Question!!     Rank Answer Posted By  
 
  Re: how to exchnage bits in a byte b7<-->b0 b6<-->b1 b5<-->b2 b4<-->b3 please mail me the code if any one know to rajeshmb4u@gmail.com
Answer
# 1
can be done by reversing the bits
 
Is This Answer Correct ?    0 Yes 0 No
Suresh
 
  Re: how to exchnage bits in a byte b7<-->b0 b6<-->b1 b5<-->b2 b4<-->b3 please mail me the code if any one know to rajeshmb4u@gmail.com
Answer
# 2
#include<stdio.h>
#include<conio.h>

int main()
{
	int i,number,count=0,a[100];

	printf("Enter the number\n");
	scanf("%d",&number);

	for(i=7;i>=0;i--)
	{
        if((1<<i) & number)
			a[count] = 1;
		else
			a[count] = 0;
		
		count++;
	}

	printf("Binary Value of the Given Number is:\n");
	for(i=0;i<=7;i++)
	{
		printf("%d",a[i]);
	}
	printf("\nReversed Binary Value of the Given Number is:\n");
	for(i=0;i<=7;i++)
	{
		printf("%d",a[7-i]);
	}
	printf("\n");
}
 
Is This Answer Correct ?    0 Yes 2 No
Santhi Perumal
 
 
 
  Re: how to exchnage bits in a byte b7<-->b0 b6<-->b1 b5<-->b2 b4<-->b3 please mail me the code if any one know to rajeshmb4u@gmail.com
Answer
# 3
You can swap swap bits using two ways
1 ) with for loop
2 ) using recursion

#include <stdio.h>

char swap_bits_in_byte ( unsigned char byte_2_swap )
{
	unsigned char swapped_byte = 0;
	int nloop = 0;
	for( nloop = 0; nloop < 8; ++nloop ) { 
		swapped_byte = swapped_byte << 1;
		swapped_byte |= ( byte_2_swap & 1 );
		byte_2_swap = byte_2_swap >> 1;
	}
	return ( swapped_byte );
}


unsigned char swap_bits ( unsigned char byte_2_swap, int 
n_size )
{
	unsigned char swapped_byte = 0;
	int bits = ( ( sizeof ( unsigned char ) * 8 ) - 1 );

	if ( bits == n_size ) {
		swapped_byte = ( byte_2_swap 
				& (unsigned char) ( pow ( 
2, n_size ) ) ) 
			? ( 1 << ( bits - n_size ) ) : 0;
	} else {
		swapped_byte = swap_bits ( byte_2_swap, 
n_size + 1 );
		swapped_byte |= ( byte_2_swap 
				& (unsigned char) ( pow ( 
2, n_size ) ) ) 
			? ( 1 << ( bits - n_size ) ) : 0;
	}
	return ( swapped_byte );
}

int main ( int argc, char* argv [] )
{
	unsigned char byte = 128 | 32;
	unsigned char swapped_byte = 0;

	swapped_byte = swap_bits_in_byte ( byte );
	printf ( "\n Un Swapped Byte :%d", byte );
	printf ( "\n Swapped Byte :%d", swapped_byte );

	swapped_byte = swap_bits ( byte, 0 );
	printf ( "\n Un Swapped Byte :%d", byte );
	printf ( "\n Swapped Byte :%d", swapped_byte );

}
 
Is This Answer Correct ?    2 Yes 0 No
Abdur Rab
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
WAP to accept basic salary of an employee? Calculate it HRA=25%,DA=30%,PF=30%&net salary display all contents?  5
Is main() function predfined or userdefined?  7
#include<stdio.h> main() { char s1[]="Ramco"; char s2[]="Systems"; s1=s2; printf("%s",s1); } what will happen if you executed this code? Ramco4
write an algorithm which can find the largest number among the given list using binary search ............... this was asked in the interview Satyam2
how many header file is in C language ?  14
Design a program using an array that lists even numbers and odd numbers separately from the 12 numbers supplied by a user.  7
how can we use static and extern?and where can we use this? Excel3
we all know about the function overloading concept used in C++ and we all learnt abt that.... but that concept is already came in C in a very smaller propotion ... my question is IN WHICH CONCEPT THERE IS A USE OF FUNCTION OVERLOADING IS USED in C language????????????? Google2
Define function ?Explain about arguments? Geometric-Software2
12. Look at the Code: main() { int a[]={1,2,3},i; for(i=0;i<3;i++) { printf("%d",*a); a++; } } Which Statement is/are True w.r.t the above code? I.Executes Successfully & Prints the contents of the array II.Gives the Error:Lvalue Required III.The address of the array should not be changed IV.None of the Above. A)Only I B)Only II C)II & III D)IV Accenture4
code for copying two strings with out strcpy() function.  5
what is available in C language but not in C++?  1
What is alloca() and why is its use discouraged?  1
if a person is buying coconuts of Rs10,and then sell that coconuts of Rs9,with the loss of one rupee.After that the person became a millaniore.how? Wipro5
write the function int countchtr(char string[],int ch);which returns the number of timesthe character ch appears in the string. for example the call countchtr("she lives in Newyork",'e') would return 3.  4
Which of the following about the C comments is incorrect ? a.commentscan go over multiple lines b.comments can start any where in the line c.a line can contain comments with out any language statements d.comments can occur within comments TCS6
what are the static variables HCL7
Reverse the part of the number which is present from position i to j. Print the new number.[without using the array] eg: num=789876 i=2 j=5 778986  2
write program on arrays GE2
N O S I E R + A S T R A L ---------------- 7 2 5 6 1 3 Honeywell2
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com