read numbers

Raimo Niskanen raimo+erlang-questions@REDACTED
Thu Dec 9 14:17:24 CET 2021


On Thu, Dec 09, 2021 at 10:15:01AM +0100, Java House wrote:
> Hello
> 
> I am trying to read a file like with a series of 0s and 1s e.g.
> 
> 111011001010
> 010011101110
> 110001001010
> 001101011101
> 110100000011
> 010110110010
> 
> 
> I read the file with
> 
> {ok, Data} = file:read_file("binary.input"),

You can read the file using io:fread(IoDevice, '', "~2u"),
or some variant thereof.


> 
> which gives me a list of binaries and then by binary matching I get
> the individual numbers in binary format
> 
> parse([<<P1:8,P2:8....>>|T])
> 
> But now I am having the following problem
> 
> each P? may contain 0 or 1 but in reality it contains the ascii value
> of the character 0 or 1
> 
> that is 48 or 49.
> 
> How do a get from the ascii value the actual number 0 or 1?
> 
> 
> Kind Regards
> 
> Nikolas

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB


More information about the erlang-questions mailing list