Question: Reversed Binary Numbers (Kattis) - C Language I have problems when input is 1000000000 (upper limit); my code is posted after the problem. #include #include

Reversed Binary Numbers (Kattis) - C Language

I have problems when input is 1000000000 (upper limit); my code is posted after the problem.

Reversed Binary Numbers (Kattis) - C Language I have problems when input

#include

#include

int main(void) {

int remainder, i = 0;

long long decimal, binary = 0, reversed = 0, multiplier = 1;

scanf("%lld", &decimal); // decimal can reach up to 1000000000, which is 30-digit long in binary

while(decimal != 0) {

remainder = decimal % 2;

decimal /= 2;

binary += remainder * multiplier;

multiplier *= 10;

}

while(binary != 0) {

remainder = binary % 10;

reversed = (reversed * 10) + remainder;

binary /= 10;

}

while(reversed != 0) {

remainder = reversed % 10;

decimal += (remainder * pow(2, i));

reversed /= 10;

i++;

}

printf("%lld ", decimal);

return 0;

}

Reversed Binary Number:s Yi has moved to Sweden and now goes to school here. The first years of schooling she got in China, and the curricula do not match completely in the two countries. Yi likes mathematics, but now... The teacher explains the algorithm for subtraction on the board, and Yi is bored. Maybe it is possible to perform the same calculations on the numbers corresponding to the reversed binary representations of the numbers on the board? Yi dreams away and starts constructing a program that reverses the binary representation, in her mind. As soon as the lecture ends, she will go home and write it on her computer Task Your task will be to write a program for reversing numbers in binary. For instance, the binary representation of 13 is 1101, and reversing it gives 1011, which corresponds to number 11. Input The input contains a single line with an integer N, 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!