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   interview questions urls   External Links  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
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 0 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 ?    0 Yes 0 No
Abdur Rab
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
write a program to find the sum of the array elements in c language?  3
int arr[] = {1,2,3,4} int *ptr=arr; *(arr+3) = *++ptr + *ptr++; Final contents of arr[] Hughes4
write an algorithm which can find the largest number among the given list using binary search ............... this was asked in the interview Satyam2
main() { int i=400,j=300; printf("%d..%d"); } ME7
What's the best way to declare and define global variables?  2
How can I read a directory in a C program?  1
Identify the correct argument for the function call fflush () in ANSI C: A)stdout B)stdin C)stderr D)All the above Accenture2
Evaluate the following: int fn(int v) { if(v==1 || v==0) return 1; if(v%2==0) return fn(v/2)+2; else return fn(v-1)+3; } for fn(7); 1) 10 2) 11 3) 1  6
Blade logic interview question. 1st round is a written tests with 15 multiple questions from c and c++. All are simple basic question. Like int main () { Int i=65; Return printf(“%c”, i); } 2nd and 3rd round is technical interview. The position for which I was interview was core UNIX and c. Yes it is for system programming. The company has product name blade server. For their server they are creating their own command for their purpose. Example cd command. We can implement it in a c program by using the chdir() function. So the question asks related to PID, fork, pipe, shared memory, signal. Write a program in c which will act as cp command. BladeLogic1
what is the function of .h in #include<stdio.h> in c ? IBM4
how to convert binary to decimal and decimal to binary in C lanaguage  2
what does data structure mean?  7
what is the defrenece between structure and union  4
Write a C function to search a number in the given list of numbers. donot use printf and scanf Honeywell6
WAP to accept rollno,course name & marks of a student & display grade if total marks is above 200?  2
Write a program to interchange two variables without using the third variable? Accenture9
Which of the following are valid "include" formats? A)#include and #include[file.h] B)#include (file.h) and #include C)#include [file.h] and #include "file.h" D)#include <file.h> and #include "file.h" Accenture12
Read N characters in to an array . Use functions to do all problems and pass the address of array to function. 1. Print only the alphabets . If in upper case print in lower case vice versa.  1
what is difference between array of characters and string Accenture8
What is the difference between char a[] = "string"; and char *p = "string"; ? Honeywell7
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

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