title: What are the rules for bitmasks? Like 0xFF vs. 0xFC
body: <p>Im working on a game that creates Procedurally generated dungeons, I found an example that uses bit masking to retrieve things like room number and type of door.</p>
  
  <p>In the example he uses a bitmask to pull details from the integer for each tile. and the integer is broken down like this</p>
  
  <pre><code>0xLLSDRRET
  
  L - is the Level Number
  S - Denotes a special tile(Like Stairs)
  D - is if its a door, and what type(Door, Arch, Trapped)
  R - Room number
  E - Flags an entrance to a room
  T - Names the type of tile(Floor, Cooridor, Blocked)
  </code></pre>
  
  <p>In this He uses a bit mask to get, for instance, the room number like:</p>
  
  <pre><code>int[][] map = new int[40][40] 
  int $ROOM_ID = 0x0000FF00;
  System.out.println(map[x][y] &amp; $ROOM_ID);
  </code></pre>
  
  <p>Now with this if map[x][y] was for instance 0x00001200 the output would be 1200. This part of Masks I understand. </p>
  
  <p>But in the source $ROOM_ID is ACTUALLY 0x0000FFC0 and I dont understand what the C does,because I tried diferent values and I cant seem to grab what the C does, for example</p>
  
  <pre><code>0x00001200 output-&gt; 1200
  0x00001210 output-&gt; 1200
  0x00001220 output-&gt; 1200
  0x00001230 output-&gt; 1200
  0x00001240 output-&gt; 1240
  0x00001250 output-&gt; 1240
  0x00001260 output-&gt; 1240
  0x00001270 output-&gt; 1240
  0x00001280 output-&gt; 1280
  0x00001290 output-&gt; 1280
  0x000012A0 output-&gt; 1280
  0x000012B0 output-&gt; 1280
  0x000012C0 output-&gt; 12C0
  0x000012D0 output-&gt; 12C0
  0x000012E0 output-&gt; 12C0
  0x000012F0 output-&gt; 12C0
  </code></pre>
  
  <p>Can Someone with more knowledge of bitmasks explain why 0x0000FFC0 &amp; 0x000012F0 = 12C0?</p>