trying to convert any fundamental type to binary

it works for any input type except long long and unsigned long long

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <iomanip>

template<typename T>
void displayBits(T value)
{
	const int SHIFT = (8 * sizeof(T))-1;
	const T MASK = 1 << SHIFT;

	std::cout << value << " = ";

	for (int i = 1; i <= SHIFT + 1; i++)
	{
		std::cout << (value & MASK ? '1' : '0');
		value <<= 1;

		if (i % 8 == 0)
			std::cout << ' ';

	}
	std::cout << std::endl;
}

int main()
{
	_int64 input;

	std::cout << "Valoare: "; std::cin >> input;
	displayBits(input);
}
const T MASK = T{ 1 } << SHIFT;
how blind could I be ? thanks
Topic archived. No new replies allowed.