|Title:||Support Unsigned Values in binary Command|
|Version:||$Revision: 1.5 $|
|Author:||Pat Thoyts <patthoyts at users dot sourceforge dot net>|
|Created:||Wednesday, 27 September 2006|
|Keywords:||Tcl, binary, unsigned|
This TIP proposes to add support for unsigned values to the binary command.
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.
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:
read all bytes as unsigned
two signed bytes then two unsigned bytes
two unsigned little-endian shorts
a single big-endian unsigned short.
a single unsigned little-endian integer
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.
A reference implementation is available in SourceForge Patch 156751 .
This document is placed in the public domain.
[Index] [History] [HTML Format] [Source Format] [LaTeX Format] [Text Format] [XML Format] [*roff Format (experimental)] [RTF Format (experimental)]TIP AutoGenerator - written by Donal K. Fellows