Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Answers were Sorted based on User's Feedback



how to exchnage bits in a byte b7<-->b0 b6<-->b1 b5<-->b2 b4<-->b3 please ..

Answer / abdur rab

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

how to exchnage bits in a byte b7<-->b0 b6<-->b1 b5<-->b2 b4<-->b3 please ..

Answer / suresh

can be done by reversing the bits

Is This Answer Correct ?    1 Yes 0 No

how to exchnage bits in a byte b7<-->b0 b6<-->b1 b5<-->b2 b4<-->b3 please ..

Answer / santhi perumal

#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 3 No

Post New Answer

More C Interview Questions

the operator for exponencation is a.** b.^ c.% d.not available

5 Answers   TCS,


When is a void pointer used?

0 Answers  


What is const keyword in c?

0 Answers  


Why string is used in c?

0 Answers  


WHAT IS LOW LEVEL LANGUAGE?

2 Answers  


What is the basic structure of c?

0 Answers  


What is the purpose of ftell?

0 Answers  


.main() { char *p = "hello world!"; p[0] = 'H'; printf("%s",p); }

0 Answers   Wilco,


Why is c called "mother" language?

0 Answers  


Given a number N, product(N) is the product of the digits of N. We can then form a sequence N, product(N), product(product(N))… For example, using 99, we get the sequence 99, 99 = 81, 81 = 8. Input Format: A single integer N Output Format: A single integer which is the number of steps after which a single digit number occurs in the sequence. Sample Test Cases: Input #00: 99 Output #00: 2 Explanation: Step - 1 : 9 * 9 = 81 Step - 2 : 8 * 1 = 8 There are 2 steps to get to this single digit number. Input #01: 1137638147

2 Answers  


what is constant pointer?

3 Answers  


How can I write functions that take a variable number of arguments?

0 Answers  


Categories