2 '\" Copyright (c
) 1997 by Sun Microsystems
, Inc
.
4 '\" See the file
"license.terms" for information on usage
and redistribution
5 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7 '\" RCS: @(#) $Id: binary.n,v 1.1 2003/12/20 03:31:54 bbbush Exp $
9 '\" The definitions below are for supplemental macros used in Tcl/Tk
12 '\" .AP
type name
in/out ?indent?
13 '\" Start paragraph describing an argument to a library procedure.
14 '\" type is
type of
argument (int, etc
.), in/out is either
"in", "out",
15 '\" or "in/out" to describe whether procedure reads or modifies arg,
16 '\" and indent is equivalent to second arg of
.IP (shouldn
't ever be
17 '\" needed
; use
.AS below instead
)
20 '\" Give maximum sizes of arguments for setting tab stops. Type and
21 '\" name are examples of largest possible arguments that will be passed
22 '\" to .AP later. If args are omitted, default tab stops are used.
25 '\" Start box enclosure
. From here until next
.BE
, everything will be
26 '\" enclosed in one large box.
29 '\" End of box enclosure
.
32 '\" Begin code excerpt.
37 '\" .VS ?version? ?br?
38 '\" Begin vertical sidebar, for use in marking newly-changed parts
39 '\" of man pages
. The first argument is ignored
and used
for recording
40 '\" the version when the .VS was added, so that the sidebars can be
41 '\" found
and removed
when they reach a certain age
. If another argument
42 '\" is present, then a line break is forced before starting the sidebar.
45 '\" End of vertical sidebar
.
48 '\" Begin an indented unfilled display.
51 '\" End of indented unfilled display
.
54 '\" Start of list of standard options for a Tk widget. The
55 '\" options follow on successive lines
, in four columns separated
59 '\" End of
list of standard options
for a Tk widget
.
61 '\" .OP cmdName dbName dbClass
62 '\" Start of description of a specific option. cmdName gives the
63 '\" option
's name as specified in the class command, dbName gives
64 '\" the option
's name in the option database, and dbClass gives
65 '\" the option
's class in the option database.
68 '\" Print arg1 underlined
, then print arg2 normally
.
70 '\" RCS
: @
(#) $Id: binary.n,v 1.1 2003/12/20 03:31:54 bbbush Exp $
72 '\" # Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
76 '\" # Start an argument description
80 . ie !"\\$2"" .TP \\n()Cu
85 \&\\$1 \\fI\\$2\\fP (\\$3)
98 '\" # define tabbing values for .AP
101 .if !"\\$1"" .nr )A \\w'\\$1'u+3n
104 .if !"\\$2
"" .nr
)B
\\w
'\\$2'u
+\\n()Au
+3n
105 .nr
)C
\\n()Bu
+\\w
'(in/out)'u
+2n
107 .AS Tcl_Interp Tcl_CreateInterp
in/out
108 '\" # BS - start boxed text
109 '\" # ^y = starting y location
117 .if n \l'\\n(.lu\
(ul
'
120 '\" # BE - end boxed text (draw box now)
125 .ie n \l
'\\n(^lu\(ul'
127 .\" Draw four
-sided box normally
, but don
't draw top of
128 .\" box if the box started on an earlier page.
130 \h'-1.5n
'\L'|\\n(^yu
-1v
'\l'\\n(^lu
+3n\
(ul
'\L'\\n(^tu
+1v
-\\n(^yu
'\l'|0u-1.5n\
(ul
'
133 \h'-1.5n
'\L'|\\n(^yu
-1v
'\h'\\n(^lu
+3n
'\L'\\n(^tu
+1v
-\\n(^yu
'\l'|0u-1.5n\
(ul
'
140 '\" # VS - start vertical sidebar
141 '\" # ^Y = starting y location
142 '\" # ^v = 1 (for troff; for nroff this doesn't matter)
146 .ie n 'mc \s12\(br\s0
149 '\" # VE - end of vertical sidebar
157 \h
'|\\n(^lu+3n'\L
'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h
'-|\\n(^lu+3n'
164 '\" # Special macro to handle page bottom: finish off current
165 '\" # box/sidebar if in box/sidebar mode, then invoked standard
166 '\" # page bottom macro.
173 .\" Draw three-sided box if this is the box's first page
,
174 .\" draw two sides but no top otherwise
.
175 .ie
!\\n(^b
-1 \h
'-1.5n'\L
'|\\n(^yu-1v'\l
'\\n(^lu+3n\(ul'\L
'\\n(^tu+1v-\\n(^yu'\h
'|0u'\c
176 .el \h
'-1.5n'\L
'|\\n(^yu-1v'\h
'\\n(^lu+3n'\L
'\\n(^tu+1v-\\n(^yu'\h
'|0u'\c
179 .nr ^x
\\n(^tu
+1v
-\\n(^Yu
180 \kx\h
'-\\nxu'\h
'|\\n(^lu+3n'\ky\L
'-\\n(^xu'\v'\\n(^xu'\h
'|0u'\c
193 '\" # DS - begin display
199 '\" # DE - end display
205 '\" # SO - start of list of standard options
207 .SH
"STANDARD OPTIONS"
213 '\" # SE - end of list of standard options
218 See the \\fBoptions\\fR manual entry for details on the standard options.
220 '\" # OP - start of full description for a single option
225 Command
-Line Name
: \\fB
\\$1
\\fR
226 Database Name
: \\fB
\\$2
\\fR
227 Database Class
: \\fB
\\$3
\\fR
231 '\" # CS - begin code excerpt
237 '\" # CE - end code excerpt
245 .TH binary n
8.0 Tcl
"Tcl Built-In Commands"
247 '\" Note: do not modify the .SH NAME line immediately below!
249 binary \- Insert and extract fields from binary strings
251 \fBbinary format \fIformatString \fR?\fIarg arg ...\fR?
253 \fBbinary scan \fIstring formatString \fR?\fIvarName varName ...\fR?
258 This command provides facilities for manipulating binary data. The
259 first form, \fBbinary format\fR, creates a binary string from normal
260 Tcl values. For example, given the values 16 and 22, on a 32 bit
261 architecture, it might produce an 8-byte binary string consisting of
262 two 4-byte integers, one for each of the numbers. The second form of
263 the command, \fBbinary scan\fR, does the opposite: it extracts data
264 from a binary string and returns it as ordinary Tcl string values.
268 The \fBbinary format\fR command generates a binary string whose layout
269 is specified by the \fIformatString\fR and whose contents come from
270 the additional arguments. The resulting binary value is returned.
272 The \fIformatString\fR consists of a sequence of zero or more field
273 specifiers separated by zero or more spaces. Each field specifier is
274 a single type character followed by an optional numeric \fIcount\fR.
275 Most field specifiers consume one argument to obtain the value to be
276 formatted. The type character specifies how the value is to be
277 formatted. The \fIcount\fR typically indicates how many items of the
278 specified type are taken from the value. If present, the \fIcount\fR
279 is a non-negative decimal integer or \fB*\fR, which normally indicates
280 that all of the items in the value are to be used. If the number of
281 arguments does not match the number of fields in the format string
282 that consume arguments, then an error is generated.
284 Each type-count pair moves an imaginary cursor through the binary
285 data, storing bytes at the current position and advancing the cursor
286 to just after the last byte stored. The cursor is initially at
287 position 0 at the beginning of the data. The type may be any one of
288 the following characters:
290 Stores a character string of length \fIcount\fR in the output string.
291 If \fIarg\fR has fewer than \fIcount\fR bytes, then additional zero
292 bytes are used to pad out the field. If \fIarg\fR is longer than the
293 specified length, the extra characters will be ignored. If
294 \fIcount\fR is \fB*\fR, then all of the bytes in \fIarg\fR will be
295 formatted. If \fIcount\fR is omitted, then one character will be
296 formatted. For example,
299 \fBbinary format a7a*a alpha bravo charlie\fR
301 will return a string equivalent to \fBalpha\\000\\000bravoc\fR.
304 This form is the same as \fBa\fR except that spaces are used for
305 padding instead of nulls. For example,
308 \fBbinary format A6A*A alpha bravo charlie\fR
310 will return \fBalpha bravoc\fR.
313 Stores a string of \fIcount\fR binary digits in low-to-high order
314 within each byte in the output string. \fIArg\fR must contain a
315 sequence of \fB1\fR and \fB0\fR characters. The resulting bytes are
316 emitted in first to last order with the bits being formatted in
317 low-to-high order within each byte. If \fIarg\fR has fewer than
318 \fIcount\fR digits, then zeros will be used for the remaining bits.
319 If \fIarg\fR has more than the specified number of digits, the extra
320 digits will be ignored. If \fIcount\fR is \fB*\fR, then all of the
321 digits in \fIarg\fR will be formatted. If \fIcount\fR is omitted,
322 then one digit will be formatted. If the number of bits formatted
323 does not end at a byte boundary, the remaining bits of the last byte
324 will be zeros. For example,
327 \fBbinary format b5b* 11100 111000011010\fR
329 will return a string equivalent to \fB\\x07\\x87\\x05\fR.
332 This form is the same as \fBb\fR except that the bits are stored in
333 high-to-low order within each byte. For example,
336 \fBbinary format B5B* 11100 111000011010\fR
338 will return a string equivalent to \fB\\xe0\\xe1\\xa0\fR.
341 Stores a string of \fIcount\fR hexadecimal digits in low-to-high
342 within each byte in the output string. \fIArg\fR must contain a
343 sequence of characters in the set ``0123456789abcdefABCDEF''. The
344 resulting bytes are emitted in first to last order with the hex digits
345 being formatted in low-to-high order within each byte. If \fIarg\fR
346 has fewer than \fIcount\fR digits, then zeros will be used for the
347 remaining digits. If \fIarg\fR has more than the specified number of
348 digits, the extra digits will be ignored. If \fIcount\fR is
349 \fB*\fR, then all of the digits in \fIarg\fR will be formatted. If
350 \fIcount\fR is omitted, then one digit will be formatted. If the
351 number of digits formatted does not end at a byte boundary, the
352 remaining bits of the last byte will be zeros. For example,
355 \fBbinary format h3h* AB def\fR
357 will return a string equivalent to \fB\\xba\\x00\\xed\\x0f\fR.
360 This form is the same as \fBh\fR except that the digits are stored in
361 high-to-low order within each byte. For example,
364 \fBbinary format H3H* ab DEF\fR
366 will return a string equivalent to \fB\\xab\\x00\\xde\\xf0\fR.
369 Stores one or more 8-bit integer values in the output string. If no
370 \fIcount\fR is specified, then \fIarg\fR must consist of an integer
371 value; otherwise \fIarg\fR must consist of a list containing at least
372 \fIcount\fR integer elements. The low-order 8 bits of each integer
373 are stored as a one-byte value at the cursor position. If \fIcount\fR
374 is \fB*\fR, then all of the integers in the list are formatted. If
375 the number of elements in the list is fewer than \fIcount\fR, then an
376 error is generated. If the number of elements in the list is greater
377 than \fIcount\fR, then the extra elements are ignored. For example,
380 \fBbinary format c3cc* {3 -3 128 1} 260 {2 5}\fR
382 will return a string equivalent to
383 \fB\\x03\\xfd\\x80\\x04\\x02\\x05\fR, whereas
385 \fBbinary format c {2 5}\fR
387 will generate an error.
390 This form is the same as \fBc\fR except that it stores one or more
391 16-bit integers in little-endian byte order in the output string. The
392 low-order 16-bits of each integer are stored as a two-byte value at
393 the cursor position with the least significant byte stored first. For
397 \fBbinary format s3 {3 -3 258 1}\fR
399 will return a string equivalent to
400 \fB\\x03\\x00\\xfd\\xff\\x02\\x01\fR.
403 This form is the same as \fBs\fR except that it stores one or more
404 16-bit integers in big-endian byte order in the output string. For
408 \fBbinary format S3 {3 -3 258 1}\fR
410 will return a string equivalent to
411 \fB\\x00\\x03\\xff\\xfd\\x01\\x02\fR.
414 This form is the same as \fBc\fR except that it stores one or more
415 32-bit integers in little-endian byte order in the output string. The
416 low-order 32-bits of each integer are stored as a four-byte value at
417 the cursor position with the least significant byte stored first. For
421 \fBbinary format i3 {3 -3 65536 1}\fR
423 will return a string equivalent to
424 \fB\\x03\\x00\\x00\\x00\\xfd\\xff\\xff\\xff\\x00\\x00\\x01\\x00\fR
427 This form is the same as \fBi\fR except that it stores one or more one
428 or more 32-bit integers in big-endian byte order in the output string.
432 \fBbinary format I3 {3 -3 65536 1}\fR
434 will return a string equivalent to
435 \fB\\x00\\x00\\x00\\x03\\xff\\xff\\xff\\xfd\\x00\\x01\\x00\\x00\fR
438 This form is the same as \fBc\fR except that it stores one or more one
439 or more single-precision floating in the machine's native
440 representation
in the output
string. This representation is not
441 portable across architectures
, so it should not be used to communicate
442 floating point numbers across the network
. The size of a floating
443 point number may vary across architectures
, so the number of bytes
444 that are generated may vary
. If the value overflows the
445 machine
's native representation, then the value of FLT_MAX
446 as defined by the system will be used instead. Because Tcl uses
447 double-precision floating-point numbers internally, there may be some
448 loss of precision in the conversion to single-precision. For example,
449 on a Windows system running on an Intel Pentium processor,
452 \fBbinary format f2 {1.6 3.4}\fR
454 will return a string equivalent to
455 \fB\\xcd\\xcc\\xcc\\x3f\\x9a\\x99\\x59\\x40\fR.
458 This form is the same as \fBf\fR except that it stores one or more one
459 or more double-precision floating in the machine's native
460 representation
in the output
string. For example
, on a
461 Windows system running on an Intel Pentium processor
,
464 \fBbinary format d1
{1.6}\fR
466 will return a
string equivalent to
467 \fB
\\x9a
\\x99
\\x99
\\x99
\\x99
\\x99
\\xf9
\\x3f
\fR
.
470 Stores
\fIcount
\fR
null bytes
in the output
string. If
\fIcount
\fR is
471 not specified
, stores one
null byte. If
\fIcount
\fR is
\fB
*\fR
,
472 generates an error
. This
type does not consume an argument
. For
476 \fBbinary format a3xa3x2a3 abc
def ghi
\fR
478 will return a
string equivalent to
\fBabc
\\000def
\\000\\000ghi
\fR
.
481 Moves the cursor back
\fIcount
\fR bytes
in the output
string. If
482 \fIcount
\fR is
\fB
*\fR or is larger than the current cursor position
,
483 then the cursor is positioned at location
0 so that the next
byte
484 stored will be the first
byte in the result
string. If
\fIcount
\fR is
485 omitted then the cursor is moved back one
byte. This
type does not
486 consume an argument
. For example
,
489 \fBbinary format a3X
*a3X2a3 abc
def ghi
\fR
491 will return
\fBdghi
\fR
.
494 Moves the cursor to the absolute location
in the output
string
495 specified by
\fIcount
\fR
. Position
0 refers to the first
byte in the
496 output
string. If
\fIcount
\fR refers to a position beyond the last
497 byte stored so far
, then
null bytes will be placed
in the unitialized
498 locations
and the cursor will be placed at the specified location
. If
499 \fIcount
\fR is
\fB
*\fR
, then the cursor is moved to the current end of
500 the output
string. If
\fIcount
\fR is omitted
, then an error will be
501 generated
. This
type does not consume an argument
. For example
,
504 \fBbinary format a5@
2a1@
*a3@
10a1 abcde f ghi j
\fR
506 will return
\fBabfdeghi
\\000\\000j
\fR
.
511 The
\fBbinary scan
\fR command parses fields from a binary
string,
512 returning the number of conversions performed
. \fIString
\fR gives the
513 input to be parsed
and \fIformatString
\fR indicates how to parse it
.
514 Each
\fIvarName
\fR gives the name of a variable
; when a field is
515 scanned from
\fIstring
\fR the result is assigned to the corresponding
518 As with
\fBbinary format
\fR
, the
\fIformatString
\fR consists of a
519 sequence of zero or more field specifiers separated by zero or more
520 spaces
. Each field specifier is a single
type character followed by
521 an optional numeric
\fIcount
\fR
. Most field specifiers consume one
522 argument to obtain the variable into which the scanned values should
523 be placed
. The
type character specifies how the binary data is to be
524 interpreted
. The
\fIcount
\fR typically indicates how many items of
525 the specified
type are taken from the data
. If present
, the
526 \fIcount
\fR is a non
-negative
decimal integer or
\fB
*\fR
, which
527 normally indicates that all of the remaining items
in the data are to
528 be used
. If there are not enough bytes left after the current cursor
529 position to satisfy the current field specifier
, then the
530 corresponding variable is left untouched
and \fBbinary scan
\fR returns
531 immediately with the number of variables that were set
. If there are
532 not enough arguments
for all of the fields
in the format
string that
533 consume arguments
, then an error is generated
.
535 It is
\fBimportant
\fR to note that the
\fBc
\fR
, \fBs
\fR
, and \fBS
\fR
536 (and \fBi
\fR
and \fBI
\fR on
64bit systems
) will be scanned into
537 long data size values
. In doing
this, values that have their high
538 bit
set (0x80 for chars
, 0x8000 for shorts
, 0x80000000 for ints
),
539 will be sign extended
. Thus the following will occur
:
541 \fBset signShort
[binary format s1
0x8000]\fR
542 \fBbinary scan $signShort s1 val
; \fI
# val == 0xFFFF8000\fR
544 If you want to produce an unsigned value
, then you can mask the return
545 value to the desired size
. For example
, to produce an unsigned
short
548 \fBset val
[expr
{$val
& 0xFFFF}]; \fI
# val == 0x8000\fR
551 Each
type-count pair moves an imaginary cursor through the binary data
,
552 reading bytes from the current position
. The cursor is initially
553 at position
0 at the beginning of the data
. The
type may be any one of
554 the following characters
:
556 The data is a character
string of length
\fIcount
\fR
. If
\fIcount
\fR
557 is
\fB
*\fR
, then all of the remaining bytes
in \fIstring
\fR will be
558 scanned into the variable
. If
\fIcount
\fR is omitted
, then one
559 character will be scanned
. For example
,
562 \fBbinary scan abcde
\\000fghi a6a10 var1 var2
\fR
564 will return
\fB
1\fR with the
string equivalent to
\fBabcde
\\000\fR
565 stored
in \fBvar
1\fR
and \fBvar
2\fR left unmodified
.
568 This form is the same
as \fBa
\fR
, except trailing blanks
and nulls are stripped from
569 the scanned value before it is stored
in the variable
. For example
,
572 \fBbinary scan
"abc efghi \\000" A
* var1
\fR
574 will return
\fB
1\fR with
\fBabc efghi
\fR stored
in \fBvar
1\fR
.
577 The data is turned into a
string of
\fIcount
\fR binary digits
in
578 low
-to
-high order represented
as a sequence of ``
1'' and ``
0''
579 characters
. The data bytes are scanned
in first to last order with
580 the bits being taken
in low
-to
-high order within each
byte. Any extra
581 bits
in the last
byte are ignored
. If
\fIcount
\fR is
\fB
*\fR
, then
582 all of the remaining bits
in \fBstring
\fR will be scanned
. If
583 \fIcount
\fR is omitted
, then one bit will be scanned
. For example
,
586 \fBbinary scan
\\x07
\\x87
\\x05 b5b
* var1 var2
\fR
588 will return
\fB
2\fR with
\fB
11100\fR stored
in \fBvar
1\fR
and
589 \fB
1110000110100000\fR stored
in \fBvar
2\fR
.
592 This form is the same
as \fBb
\fR
, except the bits are taken
in
593 high
-to
-low order within each
byte. For example
,
596 \fBbinary scan
\\x70
\\x87
\\x05 B5B
* var1 var2
\fR
598 will return
\fB
2\fR with
\fB
01110\fR stored
in \fBvar
1\fR
and
599 \fB
1000011100000101\fR stored
in \fBvar
2\fR
.
602 The data is turned into a
string of
\fIcount
\fR hexadecimal digits
in
603 low
-to
-high order represented
as a sequence of characters
in the set
604 ``
0123456789abcdef
''. The data bytes are scanned
in first to last
605 order with the hex digits being taken
in low
-to
-high order within each
606 byte. Any extra bits
in the last
byte are ignored
. If
\fIcount
\fR
607 is
\fB
*\fR
, then all of the remaining hex digits
in \fBstring
\fR will be
608 scanned
. If
\fIcount
\fR is omitted
, then one hex digit will be
609 scanned
. For example
,
612 \fBbinary scan
\\x07
\\x86
\\x05 h3h
* var1 var2
\fR
614 will return
\fB
2\fR with
\fB
706\fR stored
in \fBvar
1\fR
and
615 \fB
50\fR stored
in \fBvar
2\fR
.
618 This form is the same
as \fBh
\fR
, except the digits are taken
in
619 high
-to
-low order within each
byte. For example
,
622 \fBbinary scan
\\x07
\\x86
\\x05 H3H
* var1 var2
\fR
624 will return
\fB
2\fR with
\fB
078\fR stored
in \fBvar
1\fR
and
625 \fB
05\fR stored
in \fBvar
2\fR
.
628 The data is turned into
\fIcount
\fR
8-bit signed integers
and stored
629 in the corresponding variable
as a
list. If
\fIcount
\fR is
\fB
*\fR
,
630 then all of the remaining bytes
in \fBstring
\fR will be scanned
. If
631 \fIcount
\fR is omitted
, then one
8-bit integer will be scanned
. For
635 \fBbinary scan
\\x07
\\x86
\\x05 c2c
* var1 var2
\fR
637 will return
\fB
2\fR with
\fB
7 -122\fR stored
in \fBvar
1\fR
and \fB
5\fR
638 stored
in \fBvar
2\fR
. Note that the integers returned are signed
, but
639 they can be converted to unsigned
8-bit quantities
using an expression
642 \fBexpr
( $num
+ 0x100 ) % 0x100\fR
646 The data is interpreted
as \fIcount
\fR
16-bit signed integers
647 represented
in little
-endian
byte order
. The integers are stored
in
648 the corresponding variable
as a
list. If
\fIcount
\fR is
\fB
*\fR
, then
649 all of the remaining bytes
in \fBstring
\fR will be scanned
. If
650 \fIcount
\fR is omitted
, then one
16-bit integer will be scanned
. For
654 \fBbinary scan
\\x05
\\x00
\\x07
\\x00
\\xf0
\\xff s2s
* var1 var2
\fR
656 will return
\fB
2\fR with
\fB
5 7\fR stored
in \fBvar
1\fR
and \fB
-16\fR
657 stored
in \fBvar
2\fR
. Note that the integers returned are signed
, but
658 they can be converted to unsigned
16-bit quantities
using an expression
661 \fBexpr
( $num
+ 0x10000 ) % 0x10000\fR
665 This form is the same
as \fBs
\fR except that the data is interpreted
666 as \fIcount
\fR
16-bit signed integers represented
in big
-endian
byte
670 \fBbinary scan
\\x00
\\x05
\\x00
\\x07
\\xff
\\xf0 S2S
* var1 var2
\fR
672 will return
\fB
2\fR with
\fB
5 7\fR stored
in \fBvar
1\fR
and \fB
-16\fR
673 stored
in \fBvar
2\fR
.
676 The data is interpreted
as \fIcount
\fR
32-bit signed integers
677 represented
in little
-endian
byte order
. The integers are stored
in
678 the corresponding variable
as a
list. If
\fIcount
\fR is
\fB
*\fR
, then
679 all of the remaining bytes
in \fBstring
\fR will be scanned
. If
680 \fIcount
\fR is omitted
, then one
32-bit integer will be scanned
. For
684 \fBbinary scan
\\x05
\\x00
\\x00
\\x00
\\x07
\\x00
\\x00
\\x00
\\xf0
\\xff
\\xff
\\xff i2i
* var1 var2
\fR
686 will return
\fB
2\fR with
\fB
5 7\fR stored
in \fBvar
1\fR
and \fB
-16\fR
687 stored
in \fBvar
2\fR
. Note that the integers returned are signed
and
688 cannot be represented by Tcl
as unsigned values
.
691 This form is the same
as \fBI
\fR except that the data is interpreted
692 as \fIcount
\fR
32-bit signed integers represented
in big
-endian
byte
696 \fBbinary
\\x00
\\x00
\\x00
\\x05
\\x00
\\x00
\\x00
\\x07
\\xff
\\xff
\\xff
\\xf0 I2I
* var1 var2
\fR
698 will return
\fB
2\fR with
\fB
5 7\fR stored
in \fBvar
1\fR
and \fB
-16\fR
699 stored
in \fBvar
2\fR
.
702 The data is interpreted
as \fIcount
\fR single
-precision floating point
703 numbers
in the machine
's native representation. The floating point
704 numbers are stored in the corresponding variable as a list. If
705 \fIcount\fR is \fB*\fR, then all of the remaining bytes in
706 \fBstring\fR will be scanned. If \fIcount\fR is omitted, then one
707 single-precision floating point number will be scanned. The size of a
708 floating point number may vary across architectures, so the number of
709 bytes that are scanned may vary. If the data does not represent a
710 valid floating point number, the resulting value is undefined and
711 compiler dependent. For example, on a Windows system running on an
712 Intel Pentium processor,
715 \fBbinary scan \\x3f\\xcc\\xcc\\xcd f var1\fR
717 will return \fB1\fR with \fB1.6000000238418579\fR stored in
721 This form is the same as \fBf\fR except that the data is interpreted
722 as \fIcount\fR double-precision floating point numbers in the
723 machine's native representation
. For example
, on a Windows system
724 running on an Intel Pentium processor
,
727 \fBbinary scan
\\x9a
\\x99
\\x99
\\x99
\\x99
\\x99
\\xf9
\\x3f d var1
\fR
729 will return
\fB
1\fR with
\fB
1.6000000000000001\fR
730 stored
in \fBvar
1\fR
.
733 Moves the cursor forward
\fIcount
\fR bytes
in \fIstring
\fR
. If
734 \fIcount
\fR is
\fB
*\fR or is larger than the number of bytes after the
735 current cursor cursor position
, then the cursor is positioned after
736 the last
byte in \fIstring
\fR
. If
\fIcount
\fR is omitted
, then the
737 cursor is moved forward one
byte. Note that
this type does not
738 consume an argument
. For example
,
741 \fBbinary scan
\\x01
\\x02
\\x03
\\x04 x2H
* var1
\fR
743 will return
\fB
1\fR with
\fB
0304\fR stored
in \fBvar
1\fR
.
746 Moves the cursor back
\fIcount
\fR bytes
in \fIstring
\fR
. If
747 \fIcount
\fR is
\fB
*\fR or is larger than the current cursor position
,
748 then the cursor is positioned at location
0 so that the next
byte
749 scanned will be the first
byte in \fIstring
\fR
. If
\fIcount
\fR
750 is omitted then the cursor is moved back one
byte. Note that
this
751 type does not consume an argument
. For example
,
754 \fBbinary scan
\\x01
\\x02
\\x03
\\x04 c2XH
* var1 var2
\fR
756 will return
\fB
2\fR with
\fB
1 2\fR stored
in \fBvar
1\fR
and \fB
020304\fR
757 stored
in \fBvar
2\fR
.
760 Moves the cursor to the absolute location
in the data
string specified
761 by
\fIcount
\fR
. Note that position
0 refers to the first
byte in
762 \fIstring
\fR
. If
\fIcount
\fR refers to a position beyond the end of
763 \fIstring
\fR
, then the cursor is positioned after the last
byte. If
764 \fIcount
\fR is omitted
, then an error will be generated
. For example
,
767 \fBbinary scan
\\x01
\\x02
\\x03
\\x04 c2@
1H
* var1 var2
\fR
769 will return
\fB
2\fR with
\fB
1 2\fR stored
in \fBvar
1\fR
and \fB
020304\fR
770 stored
in \fBvar
2\fR
.
773 .SH
"PLATFORM ISSUES"
774 Sometimes it is desirable to format or scan integer values
in the
775 native
byte order
for the machine
. Refer to the
\fBbyteOrder
\fR
776 element of the
\fBtcl_platform
\fR
array to decide which
type character
777 to use
when formatting or scanning integers
.
780 format(n
), scan(n
), tclvars(n
)