Reputation: 7506
I would like to transform 42 (Base 10) into 000002A (Base 16) in Erlang...
I have found some pointers on the web :
io:format("~8..0B~n", [42]) -> 00000042
And
io:format("~.16B~n", [42]) -> 2A
But I cannot seems to find how to do both at the same time, I have tried :
io:format("~8..0.16B~n", [42])
Which seemed to be the logical thing, but it is not, it gives me an error.
Thanks.
Upvotes: 3
Views: 2109
Reputation: 960
Transform 42 (Base 10) into "000002A" (Base 16) in Erlang:
> io_lib:format("~8.16.0B", [42]).
> "0000002A"
Upvotes: 0
Reputation: 2723
io:format("~8.16.0B~n", [42]).
0000002A
basically, it's ~F.P.Pad where:
see the full io:format docs
Upvotes: 9