Put the following formula in each cell from A to L, for all rows from 1 to 4096

```
=IF(MOD(ROW() - 1, 2^(13 - COLUMN())) < 2^(12 - COLUMN()), 0, 1)
```

If you want the whole thing in a string **with spaces** like what you asked, put this in the last column

```
=A1 & " " & B1 & " " & C1 & " " & D1 & " " & E1 & " " & F1 & " " & G1 & " " & H1 & " " & I1 & " " & J1 & " " & K1 & " " & L1
```

Then drag the rows all the way until M4096

For a more general solution, put the number of bits in some cell, like Z1, or named cell like `NumOfBits`

and use the following formula

```
=IF(MOD(ROW() - 1, 2^(NumOfBits + 1 - COLUMN())) < 2^(NumOfBits - COLUMN()), 0, 1)
```

It can also be easily modified to use any cell as the starting cell by changing the row and column offset

Optimized version using bitwise operations instead of powers:

```
=IF(BITAND(ROW() - 1, BITLSHIFT(1, 13 - COLUMN()) - 1) < BITLSHIFT(1, 12 - COLUMN()), 0, 1)
=IF(BITAND(ROW() - 1, BITLSHIFT(1, NumOfBits + 1 - COLUMN()) - 1) < BITLSHIFT(1, NumOfBits - COLUMN()), 0, 1)
```

# Quickest way:

- Copy either of the above formulas
- Press
`F5` (or `Ctrl`+`G`) and enter A1:L4096 to select the whole range
- Press
`F2` then `Ctrl`+`V` to paste
- Press
`Ctrl`+`Shift`+`Enter`. Boom. You're done. No need to drag

It's an array formula which is much faster to calculate and produce a far smaller file

Explanation:

If we write all binary representations in rows from top to bottom, the flipping/toggling cycle of the nth-bit (counting from the lsb) is 2^{n}. In each cycle the first half (from 0 to 2^{n-1}-1) will be 0 and the last half will be 1. For example the lsb (first bit from the right) will alternate every 2^{1-1} = 1 bit, the second bit will toggle every 2^{2-1} = 2 bits...

As a result we'll take modulo 2^{n} to get number's current position in the cycle, if it's less than 2^{n-1} it's a zero bit, else it's a one.

4more comments