<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE TIP SYSTEM "http://www.tcl.tk/cgi-bin/tct/tip/tipxml.dtd">
<!-- Converted at Sun May 19 22:15:44 GMT 2013 -->
<!-- TIP AutoGenerator - written by Donal K. Fellows -->

<TIP number='343'>
<header><title>A Binary Specifier for [format/scan]</title><author address="mailto:alexandre.ferrieux@gmail.com">Alexandre Ferrieux</author><status type='project' state='final' tclversion="8.6" vote='after'>$Revision: 1.3 $</status><history></history><created day='3' month='dec' year='2008' /><keyword>Tcl binary</keyword></header>
<abstract>This TIP proposes to add a %b specifier to the <emph style="bold">format</emph> and <emph style="bold">scan</emph> commands for working with integers in base-2 representation.</abstract>
<body><section title="Background">
<para>The <emph style="bold">format</emph> and <emph style="bold">scan</emph> commands already have decimal, hexadecimal, and octal support, but people wanting binary today resort to a hack, namely going hexadecimal first and then <emph style="bold">string map</emph>ping the hex digits to their four-bits binary representations. We also already have the &quot;0b&quot; notation as input for <emph style="bold">expr</emph>. This lack is inelegant.</para>
</section>
<section title="Proposed Change">
<para>This TIP proposes to reuse the existing binary representation machinery to expose a new <emph style="bold">%b</emph> specifier:</para>
<verbatim><vline encoding='base64'>CWZvcm1hdCAlYiA1</vline><vline encoding='base64'>CT0+IDEwMQ==</vline><vline encoding='base64'>CXNjYW4gMDAwMTAxICViIHg7c2V0IHg=</vline><vline encoding='base64'>CT0+IDU=</vline></verbatim>
<para>The good properties of the existing code make the addition really painless, in that it automagically combines with the size (l,ll), width (digits), and prefix (#) modifiers:</para>
<verbatim><vline encoding='base64'>CWZvcm1hdCAlIzA2YiA1</vline><vline encoding='base64'>CT0+IDBiMDEwMQ==</vline><vline encoding='base64'>CWZvcm1hdCAlbGxiIFtleHByIHsoMioqNzItMSkvN31d</vline><vline encoding='base64'>CTEwMDEwMDEwMDEwMDEwMDEwMDEwMDEwMDEwMDEwMDEwMDEwMDEwMDEwMDEwMDEwMDEwMDEwMDEwMDEwMDEwMDEwMDEwMDE=</vline></verbatim>
</section>
<section title="Rationale">
<para>That is really low-hanging fruit. All the pieces are in place, it&apos;s just a matter of exposition. The binary representation is a nice pedagogic tool, and having it handy (rather than with a hack) is a bonus.</para>
</section>
<section title="Reference Implementation">
<para>See Patch 2368084 [<url ref="https://sourceforge.net/support/tracker.php?aid=2368084"/>].</para>
</section>
<section title="Copyright">
<para>This document has been placed in the public domain.</para>
</section>
</body></TIP>
