The concept is bit reversion ...to convert a number into reversed order of 32 bit unsigned integers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

The concept is bit reversion ...to convert a number into reversed order of 32 bit unsigned integers

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.

6th Feb 2021, 12:16 PM
Janani G
Janani G - avatar
4 Answers
+ 2
You can share link to your code in progress, so we can try to work it out as you go 👇 https://www.sololearn.com/post/75089/?ref=app
7th Feb 2021, 1:10 PM
Ipang
+ 1
Hint: Use std::vector as number container, it's a dynamic container. https://en.cppreference.com/w/cpp/container/vector Use std::bitset to work with a number. Swap bits from both edge, and get the unsigned int value using std::bitset::to_ulong() member function. https://en.cppreference.com/w/cpp/utility/bitset
7th Feb 2021, 12:06 PM
Ipang
+ 1
7th Feb 2021, 1:02 PM
Janani G
Janani G - avatar
0
sorry i am not able share the code... but here's the idea what i have... first step is obvious to convert given number into binary.. convert into a string make it a 32bit long(add zeroes on left) now starting from left multiplying each int(digit) with power of 2 and add to a variable and increase the power of 2 with each digit.. i guess that's the variable that keep accumulating is the answer.. this is the function part.. now the part for reading input... u can just store each input in a vector or array, then iterate through it replacing it with the above function's value... while printing u can print till last but two, followed by a "," and the last two values seperated with "and".
7th Feb 2021, 9:03 AM
NaSaPaKri
NaSaPaKri - avatar