How do I convert an integer to a binary in Erlang?

If you want to convert 543 to <<"543">> I don't think you can find something faster than:

1> list_to_binary(integer_to_list(543)).

Because in this case both functions implemented in C.

If you want to convert integer to the smallest possible binary representation you can use binary:encode_unsigned function from the new binary module like this:

1> binary:encode_unsigned(543).
2> binary:encode_unsigned(543, little).

For current readers, this is now implemented in R16, see

You can try something like

6> A = 12345.                       
7> B = <<A:32>>.

But this requires you to know the maximum number of bits in advance.