Advertisement
Guest User

Issue

a guest
Mar 2nd, 2013
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void BaseToBinary()
  6. {
  7. int b10 = 0; // Original Base 10 Value
  8. std::cin >> b10; // Inputting Base 10 Value
  9. double newval; // Temporary Placeholder
  10. int newb10 = b10; // Variable used to reference original Base 10 Value
  11. int a = 0; // Array Element Storage
  12.  
  13. for (int x = 1; b10 >= 1; x++)
  14. {
  15. if (b10 % 2 == 0)
  16. {
  17. b10 = b10 / 2;
  18. }
  19. else
  20. {
  21. b10 = (b10-1)/2;
  22. }
  23. a = a + 1;
  24. }
  25.  
  26. int* binary = new int [a];
  27. for (int n=1;b10>=1;n++)
  28. {
  29. if (newb10 % 2 == 0)
  30. {
  31. newb10=newb10/2;
  32. binary[n]=0;
  33. }
  34. else
  35. {
  36. newb10=(b10-1)/2;
  37. binary[a]=1;
  38. }
  39. }
  40. for (int e=newval; e >= 1; e--)
  41. {
  42. cout << binary[e] << " ";
  43. }
  44. cout << "Base 10 Value Converted To Binary." << endl;
  45. }
  46. int main()
  47. {
  48.  
  49. cout << "Enter A Base 10 Value" << endl;
  50.  
  51. BaseToBinary();
  52.  
  53.  
  54.  
  55.  
  56. system("pause");
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement