title: Define smallest possible datatype in c++ that can hold six values
body: <p>I want to define my own datatype that can hold a single one of six possible values in order to learn more about memory management in c++. In numbers, I want to be able to hold 0 through 5. Binary, It would suffice with three bits (101=5), although some (6 and 7) wont be used. The datatype should also consume as little memory as possible.</p>
  
  <p>Im not sure on how to accomplish this. First, I tried an enum with defined values for all the fields. As far as I know, the values are in hex there, so one "hexbit" should allow me  to store 0 through 15. But comparing it to a char (with sizeof) it stated that its 4 times the size of a char, and a char holds 0 through 255 if Im not misstaken.</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  enum Foo
  {
      a = 0x0, 
      b = 0x1,
      c = 0x2,
      d = 0x3,
      e = 0x4,
      f = 0x5,
  };
  
  int main()
  {
      Foo myfoo = a;
      char mychar = 'a';
  
      std::cout &lt;&lt; sizeof(myfoo); // prints 4
      std::cout &lt;&lt; sizeof(mychar); // prints 1
  
      return 1;
  }
  </code></pre>
  
  <p>Ive clearly misunderstood something, but fail to see what, so I turn to SO. :)</p>
  
  <p>Also, when writing this post I realised that I clearly lack some parts of the vocabulary. Ive made this post a community wiki, please edit it so I can learn the correct words for everything.</p>