<div dir="ltr">If you have a small amount of bytes, nox showed an interesting solution a couple days ago that relies on endianness:<div><br></div><div><div>1> <<I:32/integer>> = <<1, 2, 3, 4>>.</div><div><<1,2,3,4>></div><div>2> <<I:32/little>>.<br></div><div><<4,3,2,1>></div></div><div><br></div><div><br></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div><br></div><div><br></div><div><span style="font-size:13px"><div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><b>José Valim</b></span></div><div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><div><span style="font-family:verdana,sans-serif;font-size:x-small"><a href="http://www.plataformatec.com.br/" style="color:rgb(42,93,176)" target="_blank">www.plataformatec.com.br</a></span></div><div><span style="font-family:verdana,sans-serif;font-size:x-small">Skype: jv.ptec</span></div><div><span style="font-family:verdana,sans-serif;font-size:x-small">Founder and Lead Developer</span></div></span></div></span></div></div></div>
<br><div class="gmail_quote">On Fri, Jan 9, 2015 at 2:54 PM, Harit Himanshu <span dir="ltr"><<a href="mailto:harit.subscriptions@gmail.com" target="_blank">harit.subscriptions@gmail.com</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">This is another exercise in Programming Edition book that talk about<div><br></div><div><span style="color:rgb(0,0,0);font-family:verdana,sans-serif;font-size:18px;line-height:23.3999996185303px">reverses the order of bytes in a binary</span><br></div><div><br></div><div>So my attempt looks like </div><div><br></div><div><p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">58> B = <<1,2,3,4>>.</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)"><<1,2,3,4>></p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">59> binary_to_list(B).</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">[1,2,3,4]</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">60> lists:reverse(binary_to_list(B)).</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">[4,3,2,1]</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">61> list_to_binary(lists:reverse(binary_to_list(B))).</p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)"><<4,3,2,1>></p>
<p style="margin:0px;font-size:11px;font-family:Monaco;color:rgb(131,148,150);background-color:rgb(2,43,54)">62> </p></div><div><br></div><div><br></div><div>Wondering if there is a better way available. Any recommendations?</div><div><br></div><div>Thank you</div><span class="HOEnZb"><font color="#888888"><div>+ Harit Himanshu</div></font></span></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>