diff options
Diffstat (limited to 'sem_2/HLIN202/TP/TP7-8/ex7')
| -rw-r--r-- | sem_2/HLIN202/TP/TP7-8/ex7/exo7 | bin | 0 -> 13482 bytes | |||
| -rw-r--r-- | sem_2/HLIN202/TP/TP7-8/ex7/exo7.cpp | 22 |
2 files changed, 22 insertions, 0 deletions
diff --git a/sem_2/HLIN202/TP/TP7-8/ex7/exo7 b/sem_2/HLIN202/TP/TP7-8/ex7/exo7 Binary files differnew file mode 100644 index 0000000..ee26882 --- /dev/null +++ b/sem_2/HLIN202/TP/TP7-8/ex7/exo7 diff --git a/sem_2/HLIN202/TP/TP7-8/ex7/exo7.cpp b/sem_2/HLIN202/TP/TP7-8/ex7/exo7.cpp new file mode 100644 index 0000000..eff59d5 --- /dev/null +++ b/sem_2/HLIN202/TP/TP7-8/ex7/exo7.cpp @@ -0,0 +1,22 @@ +#include <iostream>
+#include<math.h>
+
+void codbin ( int x, int tab[32]){
+ for (int i=0; i < 32; i ++) {
+ tab[i]= x < pow(2,32-(i+1)) ? 0 : 1;
+ x = x < pow(2,32-(i+1)) ? x : x- pow(2,32-(i+1));
+ }
+}
+
+int main () {
+ int tab[32];
+ int x;
+ std::cout<< " Entrez un nombre entier positif, ce programme calcule sa valeur en binaire sur 32 bits "<<std::endl;
+ std::cin>>x;
+ codbin(x, &tab[0]);
+ for (int i=0; i < 32; i ++) {
+ std::cout<<tab[i];
+ }
+ std::cout<<std::endl;
+ return 0;
+}
|
