How to save a sequence as a plain text file?

I would like to be able to generate data files like the ones provided with NIST SP 800-22 (binary expansions of irrational constants), which contain data akin to

1010011111001


According to the documentation the following Mathematica code is used to generate the data:

BinExp[num_,d_] := Module[{n,L},
If[d > $$MaxPrecision,$$MaxPrecision = d];
n = N[num,d];
L = First[RealDigits[n,2]]
];

SE = BinExp[E,302500];
Save["data.e",{SE}];


However, when I run said code I get a file that begins with

SE = {1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, ...


What can I do to make the saved file like th first example of just the 1s and 0s?

• It is customary to stay responsive to comments as it is to provide feedback for the answers posted.
– Syed
Commented Nov 7, 2022 at 11:48

This works. But may be there is better way

SetDirectory[NotebookDirectory[]]
binExp[num_, d_] :=
Module[{n, L}, If[d > $$MaxPrecision,$$MaxPrecision = d];
n = N[num, d];
L = First[RealDigits[n, 2]]];

SE = binExp[E, 302500]

Export["data.txt", StringJoin[ToString[#] & /@ SE]];


Screen shot of the file (the line is very long, over 1 million digits) this the start of it:

Update

Another option instead of explicitly converting the output to string is to use Character8 for format thanks to suggestion by Ben Izd below.

 Export["data.txt", SE, "Character8"]


Both methods give the same exact output file.

• I believe that this is a solution! Commented Nov 7, 2022 at 14:02
• Appreciate the answer. It could be even more straightforward with "Character8" format. Commented Nov 7, 2022 at 14:18
• @BenIzd thanks, updated answer with your suggestion. Commented Nov 7, 2022 at 14:24
• You can use the Export's third argument to specify the format to make it even better ;) Commented Nov 7, 2022 at 14:28
• @BenIzd Yes, this is even better, I did not know about "character8", that is useful format to know. Commented Nov 7, 2022 at 15:05
BinExp[num_, d_] := IntegerString[Round[2^d num], 2]
SE = BinExp[E, 302500];
Export["data.txt", SE]


Maybe use Floor instead of Round, depending on what you need for the last digit.