Advertisement
Guest User

Convert_To_Deczimal

a guest
Aug 26th, 2020
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. /*int get_intlen(int i) Ein wenig Blödsinn muss sein. :D
  4. {
  5.     int len;
  6.     if (i > 0) {
  7.         for (len = 0; i > 0; len++) {
  8.             i = i / 10;
  9.         }
  10.     }
  11.     return len;
  12. }
  13.  
  14. int get_intmid(int i, int b)
  15. {
  16.     if (i > 0) {
  17.         for (int a = 0; a < b; a++) {
  18.             i = i / 10;
  19.         }
  20.     }
  21.     i = i % 10;
  22.     return i;
  23. }
  24.  
  25. int Convert_To_Deczimal_int_funny(int Binary)
  26. {
  27.     int len =  get_intlen(Binary);
  28.     int Ergebnis = 0;
  29.     bool temp;
  30.     for (size_t i = 0; i < len; i++)
  31.     {
  32.         if (!Binary / 10 <= 1)
  33.         {
  34.             Binary = Binary % 10;
  35.             temp = 0;
  36.         }
  37.         else
  38.         {
  39.             temp = get_intmid(Binary, i);
  40.         }
  41.         if ((bool)temp == true);
  42.         {
  43.             Ergebnis = (Ergebnis * 2) + get_intmid(Binary, i);
  44.         }
  45.     }
  46.     return Ergebnis;
  47. }*/
  48.  
  49. int Convert_To_Deczimal(bool Binary[], int len)
  50. {
  51.     int Ergebnis = 0;
  52.     for (size_t i = 0; i < len; i++)
  53.     {
  54.         if (Binary[i] == true);
  55.         {
  56.             Ergebnis = (Ergebnis * 2) + Binary[i];
  57.         }
  58.     }
  59.     return Ergebnis;
  60. }
  61.  
  62. int main()
  63. {
  64.     bool Binaryarray[] = { 0,1,0,1,1,0,0,1 };
  65.     int len = sizeof(Binaryarray) / sizeof(bool);
  66.     //int Binary = 01011001;
  67.  
  68.     std::cout << "Hello World!\n" << Convert_To_Deczimal(Binaryarray, len);
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement