Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- // BINARY - DECI VICE VERSA (di pa tapos)
- int dec_bin(int x) // decimal to binary start
- {
- int incr, res;
- incr = 1;
- res = 0;
- while(x != 0)
- {
- if (x % 10 == 1){
- res = res + incr;
- x = x-1;
- }
- x = x / 10;
- incr = incr*2;
- }
- cout << res;
- }
- void bin_dec(int x) // binary to decimal start
- {
- if (x / 2 != 0) {
- bin_dec(x / 2);
- }
- cout << x % 2;
- }
- void
- int main()
- {
- int order;
- int x;
- cout << "CHOOSE PROCESS\n********************\n1. DECIMAL TO BINARY\n2. BINARY TO DECIMAL\n********************" << endl;
- cout << "= ";
- cin >> order;
- if (order == 1){
- system("cls");
- cout << "Converting - DECIMAL TO BINARY" << endl;
- cout << "Enter a number: ";
- cin >> x;
- bin_dec(x);
- }
- else if (order == 2){
- bin_dec(x);
- system("cls");
- cout << "Converting - BINARY TO DECIMAL" << endl;
- cout << "Enter a number: ";
- cin >> x;
- dec_bin(x);
- }
- else{
- cout<<"Null - B O B O!";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement