title: Big binary number
body: <p>I'm trying to solve a problem, for the basic scenario it's working, nevertheless, I know that it is not optimal and has several faults.</p>
  <p>Problem:
  You are given a number n. Find the decimal value of the number formed by the concatenation of the binary representation of the first n positive integers. Print the answer 10^9 + 7.</p>
  <p>Output format:
  Print the answer modulo 10^9 + 7</p>
  <p>Constraint:
  1 &lt;= n &lt;= 10^9</p>
  <pre><code>Sample input: 3
  Sample Output: 27
  The binary representation of 1: 1
  The binary representation of 2: 10
  The binary representation of 3: 11
  Concatenated string: 11011 -&gt; Decimal representation is 27.
  </code></pre>
  <p>The first doubt that I have is: &quot;modulo 10^9 + 7&quot;, I understand is the limit for the number of chars, but I don't know how to interpret it.</p>
  <p>The second part of the question is with the solution:
  Input: 20</p>
  <pre><code>Binary representation of 2 : 10.
  Binary representation of 3 : 11
  Binary representation of 4 : 100. 
  Binary representation of 5 : 101
  Binary representation of 6 : 110
  Binary representation of 7 : 111
  Binary representation of 8 : 1000
  Binary representation of 9 : 1001
  Binary representation of 10 : 1010
  Binary representation of 11 : 1011
  Binary representation of 12 : 1100
  Binary representation of 13 : 1101
  Binary representation of 14 : 1110
  Binary representation of 15 : 1111
  Binary representation of 16 : 10000
  Binary representation of 17 : 10001
  Binary representation of 18 : 10010
  Binary representation of 19 : 10011
  The binary representation of 20: 10100
  Concatenated string: 11011100101110111100010011010101111001101111011111000010001100101001110100
  </code></pre>
  <p>How would you recommend to tackle this kind of problem?</p>
  <p>This is my current code:</p>
  <pre><code>public long FindBigNum(long n) {
      System.out.println(&quot;&quot;);
      System.out.println(&quot;Input: &quot; + n);
      StringBuilder binaryRepresentation = new StringBuilder();
      for(Long i = 1l; i &lt;= n; i++){
          System.out.println(&quot;Binary representation of &quot; + i + &quot; : &quot; + Long.toBinaryString(i));
          binaryRepresentation.append(Long.toBinaryString(i));
      }
      System.out.println(&quot;Concatenated string: &quot; + binaryRepresentation.toString());
      //System.out.println(&quot;Binary representation: &quot; + binaryRepresentation.toString());
      long longRepresentation = parseLong(binaryRepresentation.toString(), 2);
      //System.out.println(&quot;longRepresentation: &quot; + l);
      return longRepresentation;   
  }
  
  public long parseLong(String s, int base){
      return new BigInteger(s, base).longValue();
  }   
  </code></pre>