New format/fwrite options
Robert Virding
robert.virding@REDACTED
Thu Apr 11 22:17:44 CEST 2002
Robert Virding wrote:
> OK, I sat down and wrote my own version of binary/hex/based integer
> output. I prefer to use ~# for based instead of ~B as I think that
> upper/lower case letters should be about the "same thing". Comments?
>
> If Björn sends the man page source I can add some documentation as well.
>
> Robert
I should have given some examples of course:
Eshell V2001.09.13 (abort with ^G)
1> io:fwrite("~#~n", [4711]). %Default is 8
8#11147
ok
2> io:fwrite("~#~n", [-4711]).
-8#11147
ok
3> io:fwrite("~.16#~n", [-4711]).
-16#1267
ok
4> io:fwrite("~.16#~n", [4711]).
16#1267
ok
5> io:fwrite("~28.16#~n", [4711]).
16#1267
ok
6> io:fwrite("~b~n", [4711]). %Default is 32 bits
00000000000000000001001001100111
ok
7> io:fwrite("~b~n", [-4711]).
11111111111111111110110110011001
ok
8> io:fwrite("~.16b~n", [-4711]). %Default is 32 bits
1110110110011001
ok
9> io:fwrite("~.16b~n", [4711]).
0001001001100111
ok
10> io:fwrite("~.16x~n", [4711]).
1267
ok
11> io:fwrite("~.16x~n", [-4711]).
ed99
ok
12> io:fwrite("~x~n", [-4711]).
ffffed99
ok
13> io:fwrite("~x~n", [4711]).
00001267
ok
I think you get the idea. The only real question I think is if it
should be the precision field which gives the number of relevant bits in
~b/x or the field width. It might be bit of an overkill to have both
field width and "precision". Comments?
Robert
More information about the erlang-questions
mailing list