title: How to separate/decode binary string from an input file? (C)
body: <p>My program manages to read in an input text file line by line, and now I'm trying to process a specific section. The input looks like this:</p>
  
  <pre><code>^Other stuff^
  CODE
  10001100001000100000000000000000
  00000000010000110010000000100000
  10101100001001000000000000000000
  (End of file after CODE section)
  </code></pre>
  
  <p>The binary numbers is a MIPS instruction, and there can be any amount of lines (I used 3 as an example). I need to separate each 32 bit line into 6 sections: OpCode, rs, rt, rd, shamt, funct (6, 5, 5, 5, 5, 6 bits respectively).</p>
  
  <p>What I've already done: My program can already read the input text and call the proper function for each section. Here is a small snippet for context:</p>
  
  <pre><code>char line[64];
  
  int mode = 0; //for parsing sections, 1 = REGISTER, 2 = MEMORY, 3 = CODE
  
  while (fgets(line, sizeof line, filePtr) != NULL) {
      if (strcmp(line, "REGISTERS\n") == 0) {
          mode = 1;
      }
  
      else if (strcmp(line, "MEMORY\n") == 0) {
          mode = 2;
      }
  
      else if (strcmp(line, "CODE\n") == 0) {
          mode = 3;
      }
  
      switch (mode) {
      case 1:
          parseRegisters(line, registers); //this part works
          break;
      case 2:
          parseMemory(line, memory);  //this part works
          break;
      case 3:
          parseCode(line);  //have not started writing this function
          break;
      default:
          break;
      }
  </code></pre>
  
  <p>So at this section, it starts calling parseCode() for each binary line. How do I write parseCode() to separate each line into its 6 sections? I then need to perform different actions depending on what the sections decode to, but I already have that covered.</p>