Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
497 B
1
Indexable
Never
#include<iostream>
using namespace std;
void binary(int){
    int i,k;
    for(i=3;i>=0;i--){
        k=(a>>i)&1;
        cout<<k<<endl;
    }
}
int main(){
    int n;
    cout<<"enter a number"<<endl;
    cin>>n;
    cout<<"the hex equ is:"<<"%x"<<endl;
     cout<<"the oct equ is:"<<"%o"<<endl;
    cout<<"the binary equvalent:"<<binary(n)<<endl;
      cout<<"the 1s complement:"<<binary(-n-1)<<endl;
      cout<<"the 2s complement:"<<binary(-n)<<endl;
      return 0;
    }
Leave a Comment