<div dir="ltr"><div dir="ltr">Thank you Roger for the answer<div>I thought about it but since I have to parse all digits for every row that would mean a lot of entries as I have to create all possible combinations of 0/1 for every position of the row.</div><div><br></div><div>I also tried to do something like that to convert binaries to digits</div><div><pre style="color:rgb(8,8,8)">binary_to_digit(<<<span style="color:rgb(6,125,23)">"0"</span>>>) -> <span style="color:rgb(23,80,235)">0</span>;<br>binary_to_digit(<<<span style="color:rgb(6,125,23)">"1"</span>>>) -> <span style="color:rgb(23,80,235)">1</span><span style="color:rgb(0,51,179)">.</span></pre><pre style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace"><span style="color:rgb(0,51,179)">but the problem is that once you match a binary</span></pre></div><div><font face="monospace">parse([<<P1:8,P2:8....P12:8>>|T])</font><br></div></div><div><br></div>The P1 parameter is not any more binary it is integer.<div><br><div>I did a small example to show problem,</div><div>you have in the file
<span style="font-family:monospace">111011001010</span></div><div><font face="arial, sans-serif">You read it as binary which is something similar to </font><br><div><font face="monospace">12> <<</font><span style="font-family:"JetBrains Mono",monospace;color:rgb(102,14,122)">P1</span><span style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace">:</span><span style="font-family:"JetBrains Mono",monospace;color:rgb(23,80,235)">8</span><span style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace">, </span><span style="font-family:"JetBrains Mono",monospace;color:rgb(102,14,122)">P2</span><span style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace">:</span><span style="font-family:"JetBrains Mono",monospace;color:rgb(23,80,235)">8</span><span style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace">, </span><span style="font-family:"JetBrains Mono",monospace;color:rgb(102,14,122)">P3</span><span style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace">:</span><span style="font-family:"JetBrains Mono",monospace;color:rgb(23,80,235)">8</span><span style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace">, </span><span style="font-family:"JetBrains Mono",monospace;color:rgb(102,14,122)">P4</span><span style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace">:</span><span style="font-family:"JetBrains Mono",monospace;color:rgb(23,80,235)">8</span><span style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace">, </span><span style="font-family:"JetBrains Mono",monospace;color:rgb(102,14,122)">P5</span><span style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace">:</span><span style="font-family:"JetBrains Mono",monospace;color:rgb(23,80,235)">8</span><span style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace">, </span><span style="font-family:"JetBrains Mono",monospace;color:rgb(102,14,122)">P6</span><span style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace">:</span><span style="font-family:"JetBrains Mono",monospace;color:rgb(23,80,235)">8</span><span style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace">, </span><span style="font-family:"JetBrains Mono",monospace;color:rgb(102,14,122)">P7</span><span style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace">:</span><span style="font-family:"JetBrains Mono",monospace;color:rgb(23,80,235)">8</span><span style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace">, </span><span style="font-family:"JetBrains Mono",monospace;color:rgb(102,14,122)">P8</span><span style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace">:</span><span style="font-family:"JetBrains Mono",monospace;color:rgb(23,80,235)">8</span><span style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace">, </span><span style="font-family:"JetBrains Mono",monospace;color:rgb(102,14,122)">P9</span><span style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace">:</span><span style="font-family:"JetBrains Mono",monospace;color:rgb(23,80,235)">8</span><span style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace">, </span><span style="font-family:"JetBrains Mono",monospace;color:rgb(102,14,122)">P10</span><span style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace">:</span><span style="font-family:"JetBrains Mono",monospace;color:rgb(23,80,235)">8</span><span style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace">, </span><span style="font-family:"JetBrains Mono",monospace;color:rgb(102,14,122)">P11</span><span style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace">:</span><span style="font-family:"JetBrains Mono",monospace;color:rgb(23,80,235)">8</span><span style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace">, </span><span style="font-family:"JetBrains Mono",monospace;color:rgb(102,14,122)">P12</span><span style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace">:</span><span style="font-family:"JetBrains Mono",monospace;color:rgb(23,80,235)">8</span><span style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace">></span><span style="font-family:monospace">> = <<"111011001010">>.</span><br><font face="monospace"><<"111011001010">><br>13> P1.<br><b>49</b><br></font></div><div><div><font face="monospace">15> integer_to_binary(P1).<br><<"49">></font><br></div><div><br></div><div>So it seems that even though the digit is 1 Erlangs parsing/matching converts it to something else and it seems impossible to read exactly what was the original value, which is a simple 0 or 1.</div><div><br></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Στις Πέμ 9 Δεκ 2021 στις 12:09 μ.μ., ο/η Roger Lipscombe <<a href="mailto:roger@differentpla.net">roger@differentpla.net</a>> έγραψε:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">You could pattern match on the "0" and "1" directly...<br>
<br>
parse(Data) -> parse(Data, []).<br>
parse(<<"0", Rest/binary>>, Acc) -><br>
[false | parse(Rest, Acc)];<br>
parse(<<"1", Rest/binary>>, Acc) -><br>
[true | parse(Rest, Acc)];<br>
parse(<<$\n, Rest/binary>>, Acc) -><br>
parse(Rest, Acc);<br>
parse(<<>>, Acc) -> Acc.<br>
<br>
On Thu, 9 Dec 2021 at 09:15, Java House <<a href="mailto:java4dev@gmail.com" target="_blank">java4dev@gmail.com</a>> wrote:<br>
><br>
> Hello<br>
><br>
> I am trying to read a file like with a series of 0s and 1s e.g.<br>
><br>
> 111011001010<br>
> 010011101110<br>
> 110001001010<br>
> 001101011101<br>
> 110100000011<br>
> 010110110010<br>
><br>
><br>
> I read the file with<br>
><br>
> {ok, Data} = file:read_file("binary.input"),<br>
><br>
> which gives me a list of binaries and then by binary matching I get the individual numbers in binary format<br>
><br>
> parse([<<P1:8,P2:8....>>|T])<br>
><br>
> But now I am having the following problem<br>
><br>
> each P? may contain 0 or 1 but in reality it contains the ascii value of the character 0 or 1<br>
><br>
> that is 48 or 49.<br>
><br>
> How do a get from the ascii value the actual number 0 or 1?<br>
><br>
><br>
> Kind Regards<br>
><br>
> Nikolas<br>
><br>
><br>
</blockquote></div></div></div></div></div></div>