TIP #275: SUPPORT UNSIGNED VALUES IN BINARY COMMAND ===================================================== Version: $Revision: 1.5 $ Author: Pat Thoyts State: Final Type: Project Tcl-Version: 8.5 Vote: Done Created: Wednesday, 27 September 2006 URL: https://tip.tcl-lang.org275.html Post-History: ------------------------------------------------------------------------- ABSTRACT ========== This TIP proposes to add support for unsigned values to the *binary* command. RATIONALE =========== It is quite common when handling binary data to need to read unsigned values. All values read in by *binary scan* are converted to integers and sign extended, which requires code to trim the excess bits using the *expr* command if the values need to be treated as unsigned values. This makes Tcl slow when handling large quantities of binary data, for instance in crytographic or checksum functions. Simply by avoiding this *expr* operation we significantly improve the speed of processing such data. SPECIFICATION =============== The *binary scan* should be updated so as to add a flag identifier into the binary field format. This makes the field specification: ?? The flag character for unsigned fields (the only one defined) is "u", so the following are all acceptable: cu*: read all bytes as unsigned c2cu2: two signed bytes then two unsigned bytes su2: two unsigned little-endian shorts Su: a single big-endian unsigned short. iu: a single unsigned little-endian integer mu3: three unsigned machine-endian 64-bit integers. The "u" flag will be supported combined with all field types but will have no effect on non-integer types. Also the flag is valid but ignored for the *binary format* command. REFERENCE IMPLEMENTATION ========================== A reference implementation is available in SourceForge Patch 156751 []. COPYRIGHT =========== This document is placed in the public domain. ------------------------------------------------------------------------- TIP AutoGenerator - written by Donal K. Fellows