Computer Science, asked by daithankarashwini123, 10 months ago

You will be given a variable list of unknown length, containing 32-bits unsigned integers. You are required to give as output a comma separated list, showing for each element in the list the integer you get by reversing bits in its binary representation. For example, if the list is 32768, 101200 and 262144, you are expected to give as output 65536, 181501952 and 8192. Integers in the list will be given one per line.

Case 1:

For the input provided as follows:

32768
101200
262144

Output of the program will be:

65536, 181501952, 8192

Case 2:

For the input provided as follows:

10
0

Output of the program will be:

1342177280, 0

Answers

Answered by jchethanagowda
70

Answer:

+1

#include <stdio.h>

#include <math.h>

int main()

{

unsigned int i,n, in[10], z[10],rem, rev=0;

printf("Enter the value of n\n");

scanf("%d",&n);

printf("Enter the input values\n");

for(i=0;i<n;i++)

{

scanf("%u",&in[i]);

}

for(i=0;i<n;i++)

{

while(in[i]!=0)

{

rem=in[i] % 10;

rev=rev*10 +rem;

in[i]=in[i]/10;

z[i]=rev;

}

}

for(i=0;i<n;i++)

{

printf("%u",z[i]);

}

return(0);

}

Answered by davidunknown
6

Answer:

def reverse_Bits(n):

result = 0

for i in range(32):

result <<= 1

result |= n & 1

n >>= 1

b.append(result)

a=[ ]

b=[ ]

while True:

s=input()

if s=="":

break

a.append(int(s))

#print(a)

for i in a:

reverse_Bits(i)

print(str(b)[1:-1])

#print(*b, sep = ", ")

Similar questions