Wishes: hex-output

Erik Johansson <>
Wed Jan 17 17:08:52 CET 2001


----- Original Message -----
From: <>
>
> If it's going to be late Christmas season, and one could make some
> wishes, what about hex-output for io:format
>

Yes. I have always needed this. I use ~h and ~H. With the patch below you
can do:
>  io:format("~h 0x~H 16#~h\n", [51966, 51966, 51966]).
cafe 0xCAFE 16#cafe
>

/Erik


Index: lib/stdlib/src/io_lib_format.erl
===================================================================
RCS file:
/home/harpo/csd/happi/hipe/repository/ngorongoro/osh2/lib/stdlib/src/io_lib_
format.erl,v
retrieving revision 1.1.1.1
diff -r1.1.1.1 io_lib_format.erl
108a109,110
> collect_cc([$h|Fmt], [A|Args]) -> {$h,[A],Fmt,Args};
> collect_cc([$H|Fmt], [A|Args]) -> {$H,[A],Fmt,Args};
170a173,176
> control($h, [A], F, Adj, P, Pad, I) when integer(A) ->
>     string(int_to_hex(A), F, Adj, P, Pad);
> control($H, [A], F, Adj, P, Pad, I) when integer(A) ->
>     string(int_to_Hex(A), F, Adj, P, Pad);
174a181
>
390a398,412
>
> %% Int_to_hex(Integer)
> %% Convert an integer to a hexadecimal string...
>
> int_to_hex(N) when N < 10 -> [N+$0];
> int_to_hex(N) when N < 16 -> [N-10+$a];
> int_to_hex(N) ->
>   int_to_hex(N div 16) ++
>   int_to_hex(N  - (N div 16)*16).
>
> int_to_Hex(N) when N < 10 -> [N+$0];
> int_to_Hex(N) when N < 16 -> [N-10+$A];
> int_to_Hex(N) ->
>   int_to_Hex(N div 16) ++
>   int_to_Hex(N  - (N div 16)*16).





More information about the erlang-questions mailing list