This repository has been archived by the owner on Jun 16, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04cd758
commit 27c4e0c
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <iostream> | ||
#include <math.h> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
const int base_partenza = 10; | ||
const int base_arrivo = 2; | ||
|
||
int num_10; // numero preso in input | ||
int num_2 = 0; // risultato | ||
int count = 0; | ||
|
||
cout << "Numero in base 10: "; cin >> num_10; | ||
|
||
while (num_10!=0) { | ||
num_2 += (num_10%base_arrivo) * pow(base_partenza, count); | ||
num_10 /= base_arrivo; | ||
count++; | ||
} | ||
|
||
cout << "Numero in base 2: " << num_2 << endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <iostream> | ||
#include <math.h> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
const int base_partenza = 2; | ||
const int base_arrivo = 10; | ||
|
||
int num_2; // numero preso in input | ||
int num_10 = 0; // risultato | ||
int count = 0; // contatore iterazioni | ||
|
||
cout << "Numero base 2: "; cin >> num_2; | ||
|
||
while (num_2!=0) { | ||
num_10 += (num_2%base_arrivo) * pow(base_partenza, count); | ||
num_2 /= 10; | ||
count++; | ||
} | ||
|
||
cout << "Numero base 10: " << num_10 << endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <iostream> | ||
#include <iomanip> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
cout << "Numero: "; | ||
int n; | ||
cin >> n; | ||
cout << "Numero in base 16: " << hex << n << endl; | ||
cout << "Numero in base 10: " << dec << n << endl; // riporto lo stream allo stato normale | ||
} |