Hi !<div><br></div><div>I am new to Erlang, and would like to ask experienced users some advices on best practices I should adopt.</div><div><br></div><div>Right now, I would like to know what is the best way of padding a binary to a multiple of 4 bytes.</div>
<div>I have written a function like this:</div><div><br></div><div><div>pad_to4 (Bin) -></div><div>    case (size(Bin) rem 4) of</div><div><span class="Apple-tab-span" style="white-space:pre">  </span>0 -> Bin;</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>Pad -> <<Bin/binary, 0:((4-Pad)*8)>></div><div>    end.</div><div><br></div><div>I don't find it very elegant, and guess there is a better way of doing this.  Perhaps using binary comprehensions?  What is your suggestion?</div>
<div><br></div><div>Also, I was wondering why the "/binary" suffix was needed if I want to append to the Bin variable.  Intuitively, I have written <<Bin, 0:size>>, but it doesn't work.</div><div>
<br></div><div><br></div><div>Thanks in advance for your help!</div><div><br></div><div><br></div><div>Best,</div><div>Camille</div></div>