New format/fwrite options

Happi <>
Wed Mar 27 10:31:42 CET 2002

Robert Virding wrote:
> By popular (:-) request I am adding two new options to format/fwrite for
outputing integers
> in binary and hex, ~b and ~x. There is a small problem though with
negative numbers.
> For how long do you extend the representation with '1'? Seeing we have
bignums there
> is no concept of a word size.

Yippie, finaly!

To go one step further, I would like to see output in any base (~#) in this
case negative numbers would be handled wit a prefix minus. (Then you can
just copy and paste printed numbers in any base.)

Still beeing able to print hex and binary in a speciall way would be nice
and then
one could requier the user to give the wordsize for binary numbers.

Attached is an implementation of this.

1>  io:format("~#\n",[-42,4]).
2>  io:format("~b\n",[-42,4]).
3>  io:format("~b\n",[-42,32]).
4>  io:format("~x\n",[-42]).

In the attached file the base is limited to be betwen 2 and 16, since the
scanner limits the base of # to 16, but the base could be extended.

I'm Happi, you should be happy.
Praeterea censeo "0xCA" scribere Erlang posse.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: io_lib_format.erl
Type: application/octet-stream
Size: 15156 bytes
Desc: not available
URL: <>

More information about the erlang-questions mailing list