• Source
    1. #include<stdio.h>
    2. int main()
    3. {
    4. int n,i,x;
    5. printf(" Please, Enter a Number : ");
    6. scanf("%d",&n);
    7. printf("\n The binary equivalent of the number : \n ");
    8. for(i=7;i>=0;i--)
    9. {
    10. x=n&(1<<i);
    11. if(x==0)
    12. printf("0");
    13. else
    14. printf("1");
    15. }
    16. n=~n;
    17. n=n+1;
    18. printf("\n The 2's complement of the number :\n ");
    19. for(i=7;i>=0;i--)
    20. {
    21. x=n&(1<<i);
    22. if(x==0)
    23. printf("0");
    24. else
    25. printf("1");
    26. }
    27. return 0;
    28. }