<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<br>
<div class="moz-forward-container"><br>
<br>
-------- Forwarded Message --------
<table class="moz-email-headers-table" cellspacing="0"
cellpadding="0" border="0">
<tbody>
<tr>
<th valign="BASELINE" nowrap="nowrap" align="RIGHT">Subject:
</th>
<td>Re: [erlang-questions] binary_to_integer badarg</td>
</tr>
<tr>
<th valign="BASELINE" nowrap="nowrap" align="RIGHT">Date: </th>
<td>Mon, 17 Dec 2018 20:47:37 -0600</td>
</tr>
<tr>
<th valign="BASELINE" nowrap="nowrap" align="RIGHT">From: </th>
<td>Dan Sommers <a class="moz-txt-link-rfc2396E" href="mailto:2QdxY4RzWzUUiLuE@potatochowder.com"><2QdxY4RzWzUUiLuE@potatochowder.com></a></td>
</tr>
<tr>
<th valign="BASELINE" nowrap="nowrap" align="RIGHT">To: </th>
<td>Donald Steven <a class="moz-txt-link-rfc2396E" href="mailto:t6sn7gt@aim.com"><t6sn7gt@aim.com></a></td>
</tr>
</tbody>
</table>
<br>
<br>
On 12/17/18 8:35 PM, Donald Steven wrote:> Dan,<br>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">On 12/17/2018 9.15 PM, Dan Sommers wrote:
<blockquote type="cite"><pre class="moz-quote-pre" wrap="">On 12/17/18 7:04 PM, Donald Steven wrote:
<blockquote type="cite"><pre class="moz-quote-pre" wrap="">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.
</pre></blockquote>
This does what you want, but there may be
better ways (I'm an Erlang newbie, too):
<<Integer>> = Binary, Integer.
</pre></blockquote>
I'm sorry I don't understand. Let's say I have a value of <<"%">>,
and assign it to B. Let's say:
B = <<"%">>,
</pre>
</blockquote>
<br>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">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.
</pre>
</blockquote>
<br>
Strictly speaking, I don't know. :-)<br>
<br>
That said, Erlang's "=" operator isn't as assignment operator,
it's a<br>
pattern matching operator that binds its operands in the case of a<br>
match. So the following function reads one character from the file<br>
named by the given name, and returns the integer value of that<br>
character:<br>
<br>
f(FName) -><br>
{ok, Fd} = <a class="moz-txt-link-freetext" href="file:open(FName">file:open(FName</a>, [read, raw, binary]),<br>
{ok, B} = <a class="moz-txt-link-freetext" href="file:read(Fd">file:read(Fd</a>, 1),<br>
<<I>> = B,<br>
I.<br>
<br>
I think if you understand how/why the first line binds Fd to the
file<br>
descriptor, and how the second line binds B to the binary read
from the<br>
file , then you'll also be able to make sense of the third line
that<br>
binds I to the integer value of B.<br>
<br>
Please direct further inquiries to the list rather than to me
directly,<br>
and feel free to forward this entire reply to the list for further<br>
discussion.<br>
<br>
Dan<br>
</div>
</body>
</html>