title: Converting Long 64-bit Decimal to Binary
body: <p>OK, what I'm trying to accomplish is fairly straightforward although I'm still having issues.</p>
  
  <p><strong>This is my code :</strong></p>
  
  <pre><code>- (NSString*)toBin:(long)dec
  {
      long num = dec;
      NSString *res = [NSString string];
  
      for (long i=63; i&gt;=0; i--)
      {
          long div = 1&lt;&lt;i;
          if ((num&amp;div)==div) res = [res stringByAppendingString:@"1"];
          else res = [res stringByAppendingString:@"0"];
      }
  
      return res;
  }
  </code></pre>
  
  <p><strong>And this is how I'm testing it :</strong></p>
  
  <pre><code>    for (long i=1; i&lt;10; i++)
      {
          NSLog(@"%u = %@",i,[self toBin:(long)i]);
      }
  </code></pre>
  
  <p>However, the output of the above is :</p>
  
  <pre><code>1 = 0000000000000000000000000000000100000000000000000000000000000001
  2 = 0000000000000000000000000000001000000000000000000000000000000010
  3 = 0000000000000000000000000000001100000000000000000000000000000011
  4 = 0000000000000000000000000000010000000000000000000000000000000100
  5 = 0000000000000000000000000000010100000000000000000000000000000101
  6 = 0000000000000000000000000000011000000000000000000000000000000110
  7 = 0000000000000000000000000000011100000000000000000000000000000111
  8 = 0000000000000000000000000000100000000000000000000000000000001000
  9 = 0000000000000000000000000000100100000000000000000000000000001001
  </code></pre>
  
  <p>So, it's <em>almost</em> correct (as for the last 32 bits), though it seems to be duplicating itself for the top 32 bits. I guessed it had something to do with my <code>long</code> size, but <code>sizeof(long)</code> returns <code>8</code>. Any ideas?</p>