Thursday, August 25, 2011

Converting to and from hex in Erlang.

$ erl
Erlang R14B03 (erts-5.8.4) [source] [64-bit] [smp:2:2] [rq:2] [async-threads:0] [kernel-poll:false]
Eshell V5.8.4  (abort with ^G)

%% The base (16) followed by the hex value (0F), number is returned as a decimal.

1> 16#0F.

%% lets convert our value back,

2> integer_to_list(15, 16).

This is of course covered in the erlang manuals, but Its nice to have it in one place.

I regularly work in crash so, I need to do basic math in hex, which I usually do something like this

3>  integer_to_list(16#0F + 16#FF, 16).

No comments: