#include<iostream>
using namespace std;
int main()
{
int x = 0101;
cout<<x;
return 0;
}
The output I am getting is 101 but I want 0101 instead. what to do??
>Solution :
int data type in c/c++ is not shown as BINARY for us, it is shown as a decimal.
So, your 0101 is actually in decimal 101, which in binary, is:
0000 0000 0000 0000 0000 0000 0110 0101
If you want to store binary 0101, it is in decimal: 5.
so,
#include<iostream>
using namespace std;
int main()
{
int x = 5;
cout<<x;
return 0;
}
To output the number in binary form, you can apply an algorithm and/or either store it using bitset.