#include <iostream> #include <bitset> #include <cstddef> const size_t CHAR_SIZE = 8; template <typename T, size_t bitsCount = sizeof(T) * CHAR_SIZE> T reverse(T original) { T result = 0; std::bitset<bitsCount> bN(original); std::bitset<bitsCount> bR(result); std::cerr << "Original: " << bN << "\tResult: " << bR << "\n"; for (size_t i = 0; i < bitsCount; ++i) { result = result << 1; T rightBit = (original & 0x01); result = rightBit | result; original = original >> 1; std::bitset<bitsCount> bN(original); std::bitset<bitsCount> bR(result); std::cerr << "Original: " << bN << "\tResult: " << bR << "\n"; } return result; } int main() { reverse(5); }
Standard input is empty
Standard output is empty
Original: 00000000000000000000000000000101 Result: 00000000000000000000000000000000 Original: 00000000000000000000000000000010 Result: 00000000000000000000000000000001 Original: 00000000000000000000000000000001 Result: 00000000000000000000000000000010 Original: 00000000000000000000000000000000 Result: 00000000000000000000000000000101 Original: 00000000000000000000000000000000 Result: 00000000000000000000000000001010 Original: 00000000000000000000000000000000 Result: 00000000000000000000000000010100 Original: 00000000000000000000000000000000 Result: 00000000000000000000000000101000 Original: 00000000000000000000000000000000 Result: 00000000000000000000000001010000 Original: 00000000000000000000000000000000 Result: 00000000000000000000000010100000 Original: 00000000000000000000000000000000 Result: 00000000000000000000000101000000 Original: 00000000000000000000000000000000 Result: 00000000000000000000001010000000 Original: 00000000000000000000000000000000 Result: 00000000000000000000010100000000 Original: 00000000000000000000000000000000 Result: 00000000000000000000101000000000 Original: 00000000000000000000000000000000 Result: 00000000000000000001010000000000 Original: 00000000000000000000000000000000 Result: 00000000000000000010100000000000 Original: 00000000000000000000000000000000 Result: 00000000000000000101000000000000 Original: 00000000000000000000000000000000 Result: 00000000000000001010000000000000 Original: 00000000000000000000000000000000 Result: 00000000000000010100000000000000 Original: 00000000000000000000000000000000 Result: 00000000000000101000000000000000 Original: 00000000000000000000000000000000 Result: 00000000000001010000000000000000 Original: 00000000000000000000000000000000 Result: 00000000000010100000000000000000 Original: 00000000000000000000000000000000 Result: 00000000000101000000000000000000 Original: 00000000000000000000000000000000 Result: 00000000001010000000000000000000 Original: 00000000000000000000000000000000 Result: 00000000010100000000000000000000 Original: 00000000000000000000000000000000 Result: 00000000101000000000000000000000 Original: 00000000000000000000000000000000 Result: 00000001010000000000000000000000 Original: 00000000000000000000000000000000 Result: 00000010100000000000000000000000 Original: 00000000000000000000000000000000 Result: 00000101000000000000000000000000 Original: 00000000000000000000000000000000 Result: 00001010000000000000000000000000 Original: 00000000000000000000000000000000 Result: 00010100000000000000000000000000 Original: 00000000000000000000000000000000 Result: 00101000000000000000000000000000 Original: 00000000000000000000000000000000 Result: 01010000000000000000000000000000 Original: 00000000000000000000000000000000 Result: 10100000000000000000000000000000