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

<TIP number='129'>
<header><title>New Format Codes for the [binary] Command</title><author address="mailto:arjen.markus@wldelft.nl">Arjen Markus</author><author address="mailto:reincke@typoscriptics.de">Torsten Reincke</author><status type='project' state='final' tclversion="8.5" vote='after'>$Revision: 1.5 $</status><history></history><created day='14' month='mar' year='2003' /><keyword>IEEE {binary data} Tcl</keyword></header>
<abstract>This TIP proposes to add a set of new format codes to the <emph style="bold">binary</emph> command to enhance its ability to deal with especially non-native floating-point data. The assumption is that current limitations are due to the distinction between little-endian and big-endian storage of such data.</abstract>
<body><section title="Introduction">
<para>The current <emph style="bold">binary</emph> command can manipulate little-endian and big-endian <emph style="italic">integer</emph> data, but only <emph style="italic">native</emph> floating-point data. This means that binary data from other computer systems that use a different representation of floating-point data can not be directly handled.</para>
<para>The lack of format codes to handle &quot;native&quot; integer data means that one has to distinguish the current platform&apos;s byte ordering to be platform-independent, whenever the <emph style="bold">binary</emph> command is used.</para>
<para>Most current computer systems use either little-endian or big-endian byte order and the so-called IEEE representation for the exponent and mantissa. So, the main variation to deal with is the endian-ness.</para>
<para>Some popular file formats, like ESRI&apos;s ArcView shape files, use both types of byte order. It is difficult (though not impossible) to handle these files with the current set of format codes.</para>
<para>It should be noted that there <emph style="italic">is</emph> more variety among floating-point representation than just the byte order. This TIP will not solve this more general problem.</para>
</section>
<section title="Proposed Format Codes">
<para>Format codes should be available to catch the two main varieties of byte ordering. There should, both for reasons of symmetry and for practical purposes, also be a full set to deal with &quot;native&quot; data.</para>
<para>For integer types there are no codes to deal with native ordering. So:</para>
<itemize><item.i><para><emph style="bold">t</emph> (tiny) for short integers, using native ordering.</para></item.i><item.i><para><emph style="bold">n</emph> (normal) for ordinary integers, using native ordering.</para></item.i><item.i><para><emph style="bold">m</emph> (mirror of &quot;w&quot;) for wide integers, using native ordering.</para></item.i></itemize>
<para>The floating-point types will be handled via:</para>
<itemize><item.i><para><emph style="bold">r</emph>/<emph style="bold">R</emph> (real) for single-precision reals.</para></item.i><item.i><para><emph style="bold">q</emph>/<emph style="bold">Q</emph> (mirror of &quot;d&quot;) for double-precision reals.</para></item.i></itemize>
<para>where the lower-case is associated with little-endian order and the upper-case with big-endian order.</para>
</section>
<section title="Implementation Notes">
<para>The implementation for the integer types is simple:</para>
<itemize><item.i><para>The new format codes are synonyms for the current ones, but different ones for each endian-ness.</para></item.i></itemize>
<para>The implementation for the floating-point types is somewhat more complicated, this involves adding byte swapping, if the ordering of the platform does not correspond to that of the format code.</para>
</section>
<section title="Copyright">
<para>This document is placed in the public domain.</para>
</section>
</body></TIP>
