Last active
February 12, 2016 11:00
-
-
Save mrinalwadhwa/eaff91db6d4600641ab7 to your computer and use it in GitHub Desktop.
Pad a binary with zeros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(pad_binary). | |
% http://erlang.org/pipermail/erlang-questions/2008-December/040709.html | |
-spec pad_binary_to(WidthInBytes :: pos_integer(), Raw :: binary()) -> | |
Padded :: binary(). | |
pad_binary_to(WidthInBytes, Raw) -> | |
case (WidthInBytes - size(Raw) rem WidthInBytes) rem WidthInBytes of | |
0 -> Raw; | |
N -> <<Raw/binary, 0:(N*8)>> | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment