GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

How to print 'internal way of storing' of a number ?

I need to output binary representation of a number in memory.

asked Jan 10, 2016 by no3

1 Answer

You can use bitset of C++ stl for this purpose, it changes the number in its binary representation automatically, so a simple conversion can be written as below -

#include <iostream>
#include <bitset>
using namespace std;

int main()
	char a = -62;    
	bitset<8> x(a);
	cout << x << endl;
	short b = 315;
	bitset<16> y(b);
	cout << y << endl;


answered Jan 10, 2016 by utkarsh111