Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print the binary representation of a given integer. #457

Open
rathoresrikant opened this issue Oct 24, 2018 · 3 comments
Open

Print the binary representation of a given integer. #457

rathoresrikant opened this issue Oct 24, 2018 · 3 comments
Labels

Comments

@rathoresrikant
Copy link
Owner

Programming language : Any
Directory : Algorithms

EdYuTo added a commit to EdYuTo/HacktoberFestContribute that referenced this issue Oct 24, 2018
@bicmfcs
Copy link
Contributor

bicmfcs commented Oct 24, 2018

see #466

@santiago177
Copy link
Contributor

#474

EdYuTo added a commit to EdYuTo/HacktoberFestContribute that referenced this issue Oct 24, 2018
rathoresrikant pushed a commit that referenced this issue Oct 25, 2018
@Rajputakshay
Copy link
Contributor

#include
using namespace std;
class A
{
int x,n,k,a[2000],i,j;
public:A(int o)
{k=o;}
void binary_equiv()
{i=0;
x=k;
while(x!=1)
{a[i]=x%2;
x/=2;
i+=1;}}
void display()
{
int r=1;
for(j=i-1;j>=0;j--)
{
r++;
}
n=8-r;

cout<<"\nThe binary equivalent of "<<k<<" is :";
j=1;
while(j<=n)
{ cout<<"0";
j+=1;}
cout<<"1";
for(j=i-1;j>=0;j--)
{cout<<a[j];}
}
};

int main()
{
int num;
cout<<"\nEnter the decimal number:";
cin>>num;
A obj(num);
obj.binary_equiv();
obj.display();
}

YASHYK47 added a commit to YASHYK47/HacktoberFestContribute that referenced this issue Oct 26, 2018
hg398 added a commit to hg398/HacktoberFestContribute that referenced this issue Oct 26, 2018
A short and easy STL solution to problem in C++.
rathoresrikant pushed a commit that referenced this issue Oct 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants