Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include<iostream>
  2. #include<math.h>
  3.  
  4. using namespace std;
  5.  
  6.  
  7.  
  8. int main ()
  9. {
  10. //Variable Declarations
  11. int iDigit[8];
  12. int iP;
  13. int iNumber, iTemp;
  14. int iAnswer;
  15.  
  16. iDigit[1] =0;
  17. iDigit[2]=0
  18. iDigit[3]=0;
  19. iDigit[4]=0;
  20. iDigit[5]=0;
  21. iDigit[6]=0;
  22. iDigit[7]=0;
  23. iDigit[8] = 0 ;
  24.  
  25.  
  26. cout<<"Input the number that you wish to have represented in binary"<<endl;
  27. cout<<"(Inputted number must be between 127 and -128)"<<endl;
  28. cin>>iNumber;
  29.  
  30. iTemp = abs (iNumber);
  31.  
  32. for (iP=6; iP>=0; iP--)
  33. {
  34. if (iTemp >= 2^iP)
  35. {
  36. iDigit[iP + 1]=1 ;
  37. iTemp = iTemp -2^iP ;
  38. }
  39. }
  40.  
  41.  
  42.  
  43. for (int D=8; D>=1; D--)
  44. {
  45. iAnswer=iAnswer & iDigit[D];
  46. }
  47.  
  48. cout<<iAnswer;
  49.  
  50.  
  51.  
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement