<div dir="ltr">Sorry, there was a mistake in the commit message for the fix I had previously sent. I've canceled the original pull request and created a new one. The correct branch is in:<div><br></div><div><div>git fetch git://<a href="http://github.com/jcomellas/otp.git">github.com/jcomellas/otp.git</a> jc-integer-to-binary2_1</div>
<div><br></div><a href="https://github.com/jcomellas/otp/compare/erlang:maint...jc-integer-to-binary2_1">https://github.com/jcomellas/otp/compare/erlang:maint...jc-integer-to-binary2_1</a><br><a href="https://github.com/jcomellas/otp/compare/erlang:maint...jc-integer-to-binary2_1.patch">https://github.com/jcomellas/otp/compare/erlang:maint...jc-integer-to-binary2_1.patch</a></div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Sep 9, 2013 at 2:23 PM, Juan Jose Comellas <span dir="ltr"><<a href="mailto:juanjo@comellas.org" target="_blank">juanjo@comellas.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>The <font face="courier new, monospace">integer_to_binary/2</font> function works perfectly with base 10 (because it just calls <font face="courier new, monospace">integer_to_binary/1</font>), but when used with other bases it fails when 0 or a negative number are passed as the number to convert. e.g.:</div>

<div><br></div><div><div><font face="courier new, monospace">1> integer_to_binary(0, 16).</font></div><div><font face="courier new, monospace"><<>></font></div><div><font face="courier new, monospace"><br>
</font></div>
<div><font face="courier new, monospace">2> integer_to_binary(-1, 16).</font></div><div><font face="courier new, monospace">** exception error: bad argument</font></div><div><font face="courier new, monospace">     in function  byte_size/1</font></div>

<div><font face="courier new, monospace">        called as byte_size([])</font></div><div><font face="courier new, monospace">     in call from erlang:integer_to_binary/3 </font></div><div><font face="courier new, monospace">     in call from integer_to_binary/2</font></div>

</div><div><br></div><div>The expected results are:</div><div><br></div><div><div><font face="courier new, monospace">1> integer_to_binary(0, 16).</font></div><div><font face="courier new, monospace"><<"0">></font></div>

</div><div><font face="courier new, monospace"><br></font></div><div><div><font face="courier new, monospace">2> integer_to_binary(-1, 16).</font></div></div><div><div><font face="courier new, monospace"><<"-1">></font></div>

<div><br></div><div>I've sent this change as a pull request, but on this branch there's the patch to fix this problem and some tests to cover these cases.</div><div></div></div><div><br></div><div>git fetch git://<a href="http://github.com/jcomellas/otp.git" target="_blank">github.com/jcomellas/otp.git</a> jc-integer_to_binary2</div>

<div><br></div><div><a href="https://github.com/jcomellas/otp/compare/erlang:maint...jc-integer_to_binary2" target="_blank">https://github.com/jcomellas/otp/compare/erlang:maint...jc-integer_to_binary2</a></div><div><a href="https://github.com/jcomellas/otp/compare/erlang:maint...jc-integer_to_binary2.patch" target="_blank">https://github.com/jcomellas/otp/compare/erlang:maint...jc-integer_to_binary2.patch</a></div>

</div>
</blockquote></div><br></div>