Tcl Source Code

View Ticket
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to tclconference@googlegroups.com
or submit via the online form by Sep 9.
Ticket UUID: 2368084
Title: #343: Add %b (binary) specifier to [format/scan]
Type: Patch Version: TIP Implementation
Submitter: ferrieux Created on: 2008-12-01 00:54:21
Subsystem: 23. [scan] Assigned To: hobbs
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2008-12-12 06:36:38
Resolution: Accepted Closed By: ferrieux
    Closed on: 2008-12-11 23:36:38
Description:
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 ?
User Comments: ferrieux added on 2008-12-12 06:36:38:
TIP accepted, patch committed.

ferrieux added on 2008-12-09 04:21:45:
The mention of "octal" in the previous comment is confusing. I meant, let's just leave %i in all its historical ugliness (which includes things related to octal). Anyway.

ferrieux added on 2008-12-09 04:19:36:
After discussion with Don, it appears that the [scan %i] "fix", which is orthogonal to the TIP, is a dangerous breach of compatibility. So let's leave octal in its pond for now. Patch updated to restore the aforementioned bug. Now this patch is 100% faithful to the TIP's text.
File Added: bin2.patch

ferrieux added on 2008-12-09 04:19:35:

File Added - 304588: bin2.patch

ferrieux added on 2008-12-01 07:54:21:

File Added - 303554: bin.patch

Attachments: