Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void BaseToBinary()
- {
- int b10 = 0; // Original Base 10 Value
- std::cin >> b10; // Inputting Base 10 Value
- double newval; // Temporary Placeholder
- int newb10 = b10; // Variable used to reference original Base 10 Value
- int a = 0; // Array Element Storage
- for (int x = 1; b10 >= 1; x++)
- {
- if (b10 % 2 == 0)
- {
- b10 = b10 / 2;
- }
- else
- {
- b10 = (b10-1)/2;
- }
- a = a + 1;
- }
- int* binary = new int [a];
- for (int n=1;b10>=1;n++)
- {
- if (newb10 % 2 == 0)
- {
- newb10=newb10/2;
- binary[n]=0;
- }
- else
- {
- newb10=(b10-1)/2;
- binary[a]=1;
- }
- }
- for (int e=newval; e >= 1; e--)
- {
- cout << binary[e] << " ";
- }
- cout << "Base 10 Value Converted To Binary." << endl;
- }
- int main()
- {
- cout << "Enter A Base 10 Value" << endl;
- BaseToBinary();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement