fork download
#include 
#include 
#include 

template::value>::type, class = typename std::enable_if::value>::type>
T revbits(T in)
{
    T result = 0;
    for (int i = 0; i < std::numeric_limits::digits; i++)
    {
        result <<= 1;
		result |= in & 1;
		in >>= 1;
	}
	return result;
}

int main()
{
    unsigned short in = 0x1101;
    std::cout << std::hex << std::showbase << in << '\n';
	std::cout << revbits(in) << '\n';
}
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
0x1101
0x8088