hyun
hyun

Reputation: 2143

What does 16#4000000 mean in Erlang?

I'm reading ejabberd source, specifically ejabberd_http.erl.

In the code below,

 ...
 case (State#state.sockmod):recv(State#state.socket,
                          min(Len, 16#4000000), 300000)
 of
   {ok, Data} ->
     recv_data(State, Len - byte_size(Data), <<Acc/binary, Data/binary>>);
 ...

What does 16#4000000 mean?
I've tested this in the Erlang shell.

%%erlang shell 
...

7>16#4000000.
67108864

8>is_integer(16#4000000).
true

I know it's just an integer value.

Is there any advantage to writing 16#4000000 instead of 67108864?

Upvotes: 0

Views: 234

Answers (1)

CodeWarrior
CodeWarrior

Reputation: 538

In Erlang, the number before the # is the integer base. In your example, 16#4000000 means the hexadecimal representation of 67108864. In other languages it is often represented as 0x4000000.

One reason for using the hex representation is because each digit represents 4 bits, for example 16#F is 16 (in decimal), or 1111 in binary. When working with binary processing, using base 16 makes it easier to handle and understand for the human reader.

Upvotes: 2

Related Questions