For the sake of clarity, let me emphasise that I'm
not talking about binary in the way that [binary]
does; I'm interested in dealing with binary numbers
at the script level in the same way that I can
currently manipulate octal and hex. What I seek is:
(1) a %b numeric formatter for [format] and [scan]:
[format %b 33] should yield "100001"
[format %08b 33] should yield "00100001"
[scan 1001 %b] should yield "9"
(2) binary numbers as literal numeric strings:
[expr 3 + 0b101] should yield "8"
Anyone else interested? Or is it just me?
Messing around with [binary] is just painful,
especially when dealing with arbitrary-width
binary number strings, and the [binary] man page
is uncharacteristically obscure by the usual high
standards of Tcl documentation.
--
Jonathan Bromley, Consultant
DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services
Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan...@MYCOMPANY.com
http://www.MYCOMPANY.com
The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
Reasonable idea, but won't make 8.6. Do submit a FRQ (or, better yet,
a TIP and patch) on the topic so it doesn't get forgotten.
> (2) binary numbers as literal numeric strings:
> [expr 3 + 0b101] should yield "8"
Are you using 8.5? If so, try *exactly* what you've written. :-D
Donal.
Just added patch 2368084 which does exactly that.
https://sourceforge.net/tracker/index.php?func=detail&aid=2368084&group_id=10894&atid=310894
Repeating the comment there:
The attached patch adds a %b specifier meaning 'binary' to the
[format] and
[scan] commands. It is thus continuing in the direction pioneered by
the
recent addition of "0b" in [expr]'s number parsing.
The specifier of course also works with "#" (adding "0b" if nonzero)
and
wide- and bignum modifiers (%lb, %llb).
In addition, the patch fixes the following bug in [scan]:
% scan 0b101 %i x
1
% puts $x
0
The patch includes proper tests and documentation update. Does it
really
need a TIP ?
-Alex
>> Jonathan Bromley wrote:
>> > (1) a %b numeric formatter for [format] and [scan]:
>> > [format %b 33] should yield "100001"
>> > [format %08b 33] should yield "00100001"
>> > [scan 1001 %b] should yield "9"
>
>Just added patch 2368084 which does exactly that.
>
> https://sourceforge.net/tracker/index.php?func=detail&aid=2368084&group_id=10894&atid=310894
Ummmm, wow, that was quick...
And your neat implementation probably shows why
I should not have been trusted to do the patch :-)
thanks