title: Unexpected output from adding bits to integer (cpp)
body: <h1>Problem</h1>
  <p>Hello, this is my first stack overflow question. I'm using Bit-boards to represent board states in my chess engine. Currently I have a bit-board class like so:</p>
  <pre><code>class Bitboard {
      public:
          uint64_t Board = 0ULL;
  
          void SetSquareValue(int Square) {
  
              Board |= (1ULL &lt;&lt; Square);            
  
          }
  
          void PrintBitbaord() {
              for (int rank = 0; rank &lt; 8; rank++) {
                  for (int file = 0; file &lt; 8; file++) {
                      // formula for converting row and colum to index 
                      // rank * 8 + file
                      int square = rank * 8 + file;
  
                      if (file == 0) {
                          cout &lt;&lt; 8 - rank &lt;&lt; &quot; &quot; &lt;&lt; &quot;|&quot; &lt;&lt; &quot; &quot;;
                      }
  
  
                      cout &lt;&lt; (Board &amp; (1ULL &lt;&lt; square)) ? 1 : 0;
                      cout &lt;&lt; &quot; &quot;;
                  }
                  cout &lt;&lt; endl;
              }
              cout &lt;&lt; &quot;    ---------------&quot; &lt;&lt; endl;
              cout &lt;&lt; &quot;    a b b d e f g h&quot; &lt;&lt; endl;
  
              //cout &lt;&lt; &quot;current bitboard: &quot; &lt;&lt; self &lt;&lt; endl;
          }
  };
  
  </code></pre>
  <p>I also have this enum (positioned above class in actual file):</p>
  <pre><code>enum BoardSquare {
    a8, b8, c8, d8, e8, f8, g8, h8,
    a7, b7, c7, d7, e7, f7, g7, h7,
    a6, b6, c6, d6, e6, f6, g6, h6,
    a5, b5, c5, d5, e5, f5, g5, h5,
    a4, b4, c4, d4, e4, f4, g4, h4,
    a3, b3, c3, d3, e3, f3, g3, h3,
    a2, b2, c2, d2, e2, f2, g2, h2,
    a1, b1, c1, d1, e1, f1, g1, h1
  };
  
  
  </code></pre>
  <p>My problem is in the set square value method calling that:</p>
  <p><code>TestBitboard.SetSquareValue(e2);</code></p>
  <p>Followed by:</p>
  <p><code>TestBitboard.PrintBitboard();</code></p>
  <p>Gives a strange output:</p>
  <pre><code>
  8 | 0 0 0 0 0 0 0 0 
  7 | 0 0 0 0 0 0 0 0 
  6 | 0 0 0 0 0 0 0 0 
  5 | 0 0 0 0 0 0 0 0 
  4 | 0 0 0 0 0 0 0 0 
  3 | 0 0 0 0 0 0 0 0 
  2 | 0 0 0 0 4503599627370496 0 0 0 
  1 | 0 0 0 0 0 0 0 0 
      ---------------
      a b c d e f g h
  
  </code></pre>
  <p>Compared to my desired output:</p>
  <pre><code>
  8 | 0 0 0 0 0 0 0 0 
  7 | 0 0 0 0 0 0 0 0 
  6 | 0 0 0 0 0 0 0 0 
  5 | 0 0 0 0 0 0 0 0 
  4 | 0 0 0 0 0 0 0 0 
  3 | 0 0 0 0 0 0 0 0 
  2 | 0 0 0 0 1 0 0 0 
  1 | 0 0 0 0 0 0 0 0 
      ---------------
      a b c d e f g h
  
  </code></pre>
  <p>I'm hoping someone with more experience in cpp and bit manipulation could explain why im getting this output. While im not new to programming, i am new to cpp and I've never had to mess with bits before.</p>
  <h2>What I've tried</h2>
  <p>I've watched the following videos. i have tried to use their implementations of a similar function to no avail.</p>
  <ul>
  <li><p><a href="https://youtu.be/o-ySJ2EBarY" rel="nofollow noreferrer">https://youtu.be/o-ySJ2EBarY</a></p>
  </li>
  <li><p><a href="https://youtu.be/MzfQ8H16n0M" rel="nofollow noreferrer">https://youtu.be/MzfQ8H16n0M</a></p>
  </li>
  </ul>
  <p>I've also messed around with the code swapping values, trying different enum values, etc.</p>
  <p>The most change I've been able to get is the value 4503599627370496 to change to something different but still not my desired output.</p>