Time spent here:

Thursday, 2 June 2016

Reverse a 32 bit given number.

Reverse a 32 bit given number.
Input:
The first line of input consists number of the test cases. Each test case contains a single 32 bit integer.

Output:
Print the reverse of integer.

Constraints:
1<=T<=100
0<=x<=4294967295

Example:

Input:
2
1
5

Output:
2147483648
2684354560

Explanation:
In first cases

00000000000000000000000000000001 =1
10000000000000000000000000000000 =2147483648

code:

#include <stdio.h>
#include<math.h>
int main() {
  long long int n,t,sum,count;
  scanf("%lld",&t);
  while(t--)
  {
      scanf("%lld",&n);sum=0;count=1;
      while(n)
      {
       
          if(n%2)
            sum=sum+pow(2,32-count);
          n=n/2; count++;  
      }
  printf("%lld\n",sum);
     
  }
return 0;
}

1 comment: