Question: How do I concatenate two binaries in Erlang?

For example, let's say I have:

```
B1 = <<1,2>>.
B2 = <<3,4>>.

```

How do I concatenate B1 and B2 to create a binary B3 which is <<1,2,3,4>>?

The reason I am asking this is because I am writing code to encode a packet for some networking protocol. I am implementing this by writing encoders for the fields in the packet and I need to concatenate those fields to build up the whole packet.

Maybe I am doing this the wrong way. Should I build up the packet as a list of integers and convert the list to a binary at the last moment?

Answer: 
To use an io\_list, you could do:

```
erlang:iolist_to_binary([<<"foo">>, <<"bar">>])

```

Which is nice and legible. You could also use lists and things in there if it's more convenient.
use the erlang function list\_to\_binary(List) you can find the documentation here:
<http://www.erlang.org/documentation/doc-5.4.13/lib/kernel-2.10.13/doc/html/erlang.html#list_to_binary/1>