Fwd: Re: binary_to_integer badarg

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Fwd: Re: binary_to_integer badarg

Donald Steven

-------- Forwarded Message --------
Subject: Re: [erlang-questions] binary_to_integer badarg
Date: Mon, 17 Dec 2018 20:47:37 -0600
From: Dan Sommers [hidden email]
To: Donald Steven [hidden email]

On 12/17/18 8:35 PM, Donald Steven wrote:> Dan,
On 12/17/2018 9.15 PM, Dan Sommers wrote:
On 12/17/18 7:04 PM, Donald Steven wrote:

This works fine and I'll get back, for example <<"%">>, which
is_binary tells me is a binary.  I've tried
binary_to_integer(<<"%">>) but I get a badarg error.
This does what you want, but there may be better ways (I'm an Erlang newbie, too): <<Integer>> = Binary, Integer.
I'm sorry I don't understand. Let's say I have a value of <<"%">>, and assign it to B. Let's say: B = <<"%">>,

If I want to assign the value of "%" (decimal 37) to integer I, how do
I complete the expression:

I =

such that I will equal 37.

Strictly speaking, I don't know. :-)

That said, Erlang's "=" operator isn't as assignment operator, it's a
pattern matching operator that binds its operands in the case of a
match. So the following function reads one character from the file
named by the given name, and returns the integer value of that

f(FName) ->
{ok, Fd} = file:open(FName, [read, raw, binary]),
{ok, B} = file:read(Fd, 1),
<<I>> = B,

I think if you understand how/why the first line binds Fd to the file
descriptor, and how the second line binds B to the binary read from the
file , then you'll also be able to make sense of the third line that
binds I to the integer value of B.

Please direct further inquiries to the list rather than to me directly,
and feel free to forward this entire reply to the list for further


erlang-questions mailing list
[hidden email]