title: Interpret Some Functions in C
body: <p>I was wondering if anyone can explain to me what is happening in the following chunks of code.  The code is being used to creates random connections between 7 rooms, ensuring that each room has a minimum of 3 connections.  </p>
  
  <pre><code>void bitcodeToEdge(int bitcode, int *edge)
  {
      int i = 0; 
      int j = 0; 
      while (i &lt; 2 &amp;&amp; bitcode &gt; 0) {
          if (bitcode % 2 == 1) {
              edge[i] = j;
              i++;
          }
          bitcode &gt;&gt;= 1;
          j++;
      }
      for (; i &lt; 2; ++i) edge[i] = -1;
  }
  
  void edgeToBitcode(int *edge, int *bitcode)
  {
      *bitcode = power(2, edge[0]) + power(2, edge[1]);
  }
  
  void connectRooms(int *rooms, char *dir, char **filenames, char **roomNames)
  {
      int i, j;
      FILE *file;
      char filename[100]; 
      int bitcode; 
      int edge[2]; 
      int *edges; 
      int edgeIdx;
      int maxEdges;
      int minEdges; 
      int randEdges; 
      int valencies[10]; 
      maxEdges = 21;
      edgeIdx = 0;
      edges = malloc(sizeof(int) * maxEdges);
      assert(edges != NULL);
      for (i = 0; i &lt; 10; ++i) {
          for (j = i + 1; j &lt; 10; ++j) {
              edge[0] = rooms[i];
              edge[1] = rooms[j];
              edgeToBitcode(edge, &amp;bitcode);
              edges[edgeIdx] = bitcode;
              edgeIdx++;
          }
      }
      permute(edges, maxEdges);
      for (i = 0; i &lt; 10; ++i) valencies[i] = INT_MAX;
      for (i = 0; i &lt; 7; ++i) valencies[rooms[i]] = 0;
      edgeIdx = 0;
      minEdges = 10;
      randEdges =  getRandInt(minEdges, maxEdges);
      while (edgeIdx &lt; randEdges || getIntArrayMin(valencies, 7) &lt; 3)
      {
          bitcodeToEdge(edges[edgeIdx], edge);
          valencies[edge[0]] += 1;
          valencies[edge[1]] += 1;
          for (i = 0; i &lt; 2; ++i) {
              strcpy(filename, dir);
              strcat(filename, filenames[edge[i]]);
              if ((file = fopen(filename, "a")) == NULL) {
                  fprintf(stderr, "could not open %s for writing\n", filename);
                  exit(2);
              }
              fprintf(file, "\nCONNECTION %d: %s",
              valencies[edge[i]],
              roomNames[edge[1 - i]]);
              fclose(file);
          }
          edgeIdx++;
      }
      free(edges);
  }
  </code></pre>
  
  <p>Power works just like pow - x^y<br>
  <code>GetIntArrayMin</code> gets the minimum integer value  in the array<br/>
  Permute creates a pseudo-random permutation of a specified integer array.</p>
  
  <p>I don't understand what bitcode is at all.  Maybe if someone could just explain that at first I could get an understanding of the rest.  Thank you!</p>