Wishes: hex-output, was: lists:partition/2

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Wishes: hex-output, was: lists:partition/2

Jouni Rynö-2

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

Unfortunately there should be several of them for
{ CAFE, 0xCAFE, 16#CAFE and ... ? }


  Jouni Ryn?                            mailto://Jouni.Ryno/
                                        http://www.geo.fmi.fi/~ryno/
  Finnish Meteorological Institute      http://www.fmi.fi/
  Geophysical Research                  http://www.geo.fmi.fi/
  P.O.BOX 503                           Tel   (+358)-9-19294656
  FIN-00101 Helsinki                    GSM   (+358)-50-5302903
  Finland                               FAX   (+358)-9-19294603
 
  "It's just zeros and ones, it cannot be hard"






Reply | Threaded
Open this post in threaded view
|

Wishes: hex-output

Happi

----- Original Message -----
From: <Jouni.Ryno>
>
> 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).




Reply | Threaded
Open this post in threaded view
|

Wishes: hex-output

Robert Virding-4
"Erik Johansson" <happi> writes:

>
>----- Original Message -----
>From: <Jouni.Ryno>
>>
>> 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
>>

Seems reasonable.  I'll add it. My only small qualm is that the
coupling ~h/~H does not mean the same thing as ~w/~W and ~p/~P, but I
suppose there is not real problem here.

There should be probably be a matching hex-input flag for io:fread.  I
suppose I had better do that one as well.

        Robert