title: Using typedef and struct to create bitfield
body: <p>Hey all this is for C programming.</p>
  
  <p>Here are the questions as they were presented to me, can someone tell me how I would correctly write code for the following statements in C? FYI i already answered this quiz but my professor won't post the answers himself. I did very poorly when he graded it, but <strong>to help make sense of this i will provide my answers (as incorrect as they are)</strong></p>
  
  <p>1: Create a structure that will hold bits the represent the following:</p>
  
  <ul>
  <li>count: a 4 bit BCD number</li>
  <li>red LED: 1 bit</li>
  <li>green LED: 1 bit</li>
  <li>motor direction: 2 bits</li>
  </ul>
  
  <p>Name the structure motorStatus</p>
  
  <p>Use typedef to name this new data type: mtrStatus_t</p>
  
  <pre><code>typedef unsigned char mtrStatus_t;
  
  struct motorStatus mtrStatus_t {
      mtrStatus_t count: 4;
      mtrStatus_t redLED: 1;
      mtrStatus_t greenLED: 1;
      mtrStatus_t motorDirection: 2;
  };
  </code></pre>
  
  <p>2: Create a new instance of the structure and name it motor1Status</p>
  
  <pre><code>motorStatus = motor1Status;
  </code></pre>
  
  <p>3: Write statements to initialize the new structure members as follows:</p>
  
  <ul>
  <li>count: 9 BCD</li>
  <li>red LED: 1</li>
  <li>green LED: 0</li>
  <li><p>Motor Direction: 10</p>
  
  <p>count: 0x09;
  redLED: 0x01;
  greenLED: 0x00
  motorDirection: 0x0A</p></li>
  </ul>