OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / ALPHALINUX5 / util / ALPHALINUX5 / man / mann / binary.n
1 '\"
2 '\" Copyright (c) 1997 by Sun Microsystems, Inc.
3 '\"
4 '\" See the file "license.terms" for information on usage and redistribution
5 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6 '\" 
7 '\" RCS: @(#) $Id: binary.n,v 1.4 2000/04/08 02:35:17 hobbs Exp $
8 '\" 
9 '\" The definitions below are for supplemental macros used in Tcl/Tk
10 '\" manual entries.
11 '\"
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)
18 '\"
19 '\" .AS ?type? ?name?
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.
23 '\"
24 '\" .BS
25 '\"     Start box enclosure.  From here until next .BE, everything will be
26 '\"     enclosed in one large box.
27 '\"
28 '\" .BE
29 '\"     End of box enclosure.
30 '\"
31 '\" .CS
32 '\"     Begin code excerpt.
33 '\"
34 '\" .CE
35 '\"     End code excerpt.
36 '\"
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.
43 '\"
44 '\" .VE
45 '\"     End of vertical sidebar.
46 '\"
47 '\" .DS
48 '\"     Begin an indented unfilled display.
49 '\"
50 '\" .DE
51 '\"     End of indented unfilled display.
52 '\"
53 '\" .SO
54 '\"     Start of list of standard options for a Tk widget.  The
55 '\"     options follow on successive lines, in four columns separated
56 '\"     by tabs.
57 '\"
58 '\" .SE
59 '\"     End of list of standard options for a Tk widget.
60 '\"
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.
66 '\"
67 '\" .UL arg1 arg2
68 '\"     Print arg1 underlined, then print arg2 normally.
69 '\"
70 '\" RCS: @(#) $Id: man.macros,v 1.3 1999/04/16 00:46:35 stanton Exp $
71 '\"
72 '\"     # Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
73 .if t .wh -1.3i ^B
74 .nr ^l \n(.l
75 .ad b
76 '\"     # Start an argument description
77 .de AP
78 .ie !"\\$4"" .TP \\$4
79 .el \{\
80 .   ie !"\\$2"" .TP \\n()Cu
81 .   el          .TP 15
82 .\}
83 .ta \\n()Au \\n()Bu
84 .ie !"\\$3"" \{\
85 \&\\$1  \\fI\\$2\\fP    (\\$3)
86 .\".b
87 .\}
88 .el \{\
89 .br
90 .ie !"\\$2"" \{\
91 \&\\$1  \\fI\\$2\\fP
92 .\}
93 .el \{\
94 \&\\fI\\$1\\fP
95 .\}
96 .\}
97 ..
98 '\"     # define tabbing values for .AP
99 .de AS
100 .nr )A 10n
101 .if !"\\$1"" .nr )A \\w'\\$1'u+3n
102 .nr )B \\n()Au+15n
103 .\"
104 .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
105 .nr )C \\n()Bu+\\w'(in/out)'u+2n
106 ..
107 .AS Tcl_Interp Tcl_CreateInterp in/out
108 '\"     # BS - start boxed text
109 '\"     # ^y = starting y location
110 '\"     # ^b = 1
111 .de BS
112 .br
113 .mk ^y
114 .nr ^b 1u
115 .if n .nf
116 .if n .ti 0
117 .if n \l'\\n(.lu\(ul'
118 .if n .fi
119 ..
120 '\"     # BE - end boxed text (draw box now)
121 .de BE
122 .nf
123 .ti 0
124 .mk ^t
125 .ie n \l'\\n(^lu\(ul'
126 .el \{\
127 .\"     Draw four-sided box normally, but don't draw top of
128 .\"     box if the box started on an earlier page.
129 .ie !\\n(^b-1 \{\
130 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
131 .\}
132 .el \}\
133 \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
134 .\}
135 .\}
136 .fi
137 .br
138 .nr ^b 0
139 ..
140 '\"     # VS - start vertical sidebar
141 '\"     # ^Y = starting y location
142 '\"     # ^v = 1 (for troff;  for nroff this doesn't matter)
143 .de VS
144 .if !"\\$2"" .br
145 .mk ^Y
146 .ie n 'mc \s12\(br\s0
147 .el .nr ^v 1u
148 ..
149 '\"     # VE - end of vertical sidebar
150 .de VE
151 .ie n 'mc
152 .el \{\
153 .ev 2
154 .nf
155 .ti 0
156 .mk ^t
157 \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
158 .sp -1
159 .fi
160 .ev
161 .\}
162 .nr ^v 0
163 ..
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.
167 .de ^B
168 .ev 2
169 'ti 0
170 'nf
171 .mk ^t
172 .if \\n(^b \{\
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
177 .\}
178 .if \\n(^v \{\
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
181 .\}
182 .bp
183 'fi
184 .ev
185 .if \\n(^b \{\
186 .mk ^y
187 .nr ^b 2
188 .\}
189 .if \\n(^v \{\
190 .mk ^Y
191 .\}
192 ..
193 '\"     # DS - begin display
194 .de DS
195 .RS
196 .nf
197 .sp
198 ..
199 '\"     # DE - end display
200 .de DE
201 .fi
202 .RE
203 .sp
204 ..
205 '\"     # SO - start of list of standard options
206 .de SO
207 .SH "STANDARD OPTIONS"
208 .LP
209 .nf
210 .ta 4c 8c 12c
211 .ft B
212 ..
213 '\"     # SE - end of list of standard options
214 .de SE
215 .fi
216 .ft R
217 .LP
218 See the \\fBoptions\\fR manual entry for details on the standard options.
219 ..
220 '\"     # OP - start of full description for a single option
221 .de OP
222 .LP
223 .nf
224 .ta 4c
225 Command-Line Name:      \\fB\\$1\\fR
226 Database Name:  \\fB\\$2\\fR
227 Database Class: \\fB\\$3\\fR
228 .fi
229 .IP
230 ..
231 '\"     # CS - begin code excerpt
232 .de CS
233 .RS
234 .nf
235 .ta .25i .5i .75i 1i
236 ..
237 '\"     # CE - end code excerpt
238 .de CE
239 .fi
240 .RE
241 ..
242 .de UL
243 \\$1\l'|0\(ul'\\$2
244 ..
245 .TH binary n 8.0 Tcl "Tcl Built-In Commands"
246 .BS
247 '\" Note:  do not modify the .SH NAME line immediately below!
248 .SH NAME
249 binary \- Insert and extract fields from binary strings
250 .SH SYNOPSIS
251 \fBbinary format \fIformatString \fR?\fIarg arg ...\fR?
252 .br
253 \fBbinary scan \fIstring formatString \fR?\fIvarName varName ...\fR?
254 .BE
255
256 .SH DESCRIPTION
257 .PP
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, it might produce
261 an 8-byte binary string consisting of two 4-byte integers, one for
262 each of the numbers.  The second form of the command, 
263 \fBbinary scan\fR, does the opposite: it extracts data from a binary
264 string and returns it as ordinary Tcl string values.
265
266 .SH "BINARY FORMAT"
267 .PP
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.
271 .PP
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.
283 .PP
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:
289 .IP \fBa\fR 5
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,
297 .RS
298 .CS
299 \fBbinary format a7a*a alpha bravo charlie\fR
300 .CE
301 will return a string equivalent to \fBalpha\\000\\000bravoc\fR.
302 .RE
303 .IP \fBA\fR 5
304 This form is the same as \fBa\fR except that spaces are used for
305 padding instead of nulls.  For example,
306 .RS
307 .CS
308 \fBbinary format A6A*A alpha bravo charlie\fR
309 .CE
310 will return \fBalpha bravoc\fR.
311 .RE
312 .IP \fBb\fR 5
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,
325 .RS
326 .CS
327 \fBbinary format b5b* 11100 111000011010\fR
328 .CE
329 will return a string equivalent to \fB\\x07\\x87\\x05\fR.
330 .RE
331 .IP \fBB\fR 5
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,
334 .RS
335 .CS
336 \fBbinary format B5B* 11100 111000011010\fR
337 .CE
338 will return a string equivalent to \fB\\xe0\\xe1\\xa0\fR.
339 .RE
340 .IP \fBh\fR 5
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,
353 .RS
354 .CS
355 \fBbinary format h3h* AB def\fR
356 .CE
357 will return a string equivalent to \fB\\xba\\x00\\xed\\x0f\fR.
358 .RE
359 .IP \fBH\fR 5
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,
362 .RS
363 .CS
364 \fBbinary format H3H* ab DEF\fR
365 .CE
366 will return a string equivalent to \fB\\xab\\x00\\xde\\xf0\fR.
367 .RE
368 .IP \fBc\fR 5
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,
378 .RS
379 .CS
380 \fBbinary format c3cc* {3 -3 128 1} 260 {2 5}\fR
381 .CE
382 will return a string equivalent to
383 \fB\\x03\\xfd\\x80\\x04\\x02\\x05\fR, whereas
384 .CS
385 \fBbinary format c {2 5}\fR
386 .CE
387 will generate an error.
388 .RE
389 .IP \fBs\fR 5
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
394 example,
395 .RS
396 .CS
397 \fBbinary format s3 {3 -3 258 1}\fR
398 .CE
399 will return a string equivalent to 
400 \fB\\x03\\x00\\xfd\\xff\\x02\\x01\fR.
401 .RE
402 .IP \fBS\fR 5
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
405 example,
406 .RS
407 .CS
408 \fBbinary format S3 {3 -3 258 1}\fR
409 .CE
410 will return a string equivalent to 
411 \fB\\x00\\x03\\xff\\xfd\\x01\\x02\fR.
412 .RE
413 .IP \fBi\fR 5
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
418 example,
419 .RS
420 .CS
421 \fBbinary format i3 {3 -3 65536 1}\fR
422 .CE
423 will return a string equivalent to 
424 \fB\\x03\\x00\\x00\\x00\\xfd\\xff\\xff\\xff\\x00\\x00\\x01\\x00\fR
425 .RE
426 .IP \fBI\fR 5
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.
429 For example,
430 .RS
431 .CS
432 \fBbinary format I3 {3 -3 65536 1}\fR
433 .CE
434 will return a string equivalent to 
435 \fB\\x00\\x00\\x00\\x03\\xff\\xff\\xff\\xfd\\x00\\x01\\x00\\x00\fR
436 .RE
437 .IP \fBf\fR 5
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,
450 .RS
451 .CS
452 \fBbinary format f2 {1.6 3.4}\fR
453 .CE
454 will return a string equivalent to 
455 \fB\\xcd\\xcc\\xcc\\x3f\\x9a\\x99\\x59\\x40\fR.
456 .RE
457 .IP \fBd\fR 5
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,
462 .RS
463 .CS
464 \fBbinary format d1 {1.6}\fR
465 .CE
466 will return a string equivalent to 
467 \fB\\x9a\\x99\\x99\\x99\\x99\\x99\\xf9\\x3f\fR.
468 .RE
469 .IP \fBx\fR 5
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
473 example,
474 .RS
475 .CS
476 \fBbinary format a3xa3x2a3 abc def ghi\fR
477 .CE
478 will return a string equivalent to \fBabc\\000def\\000\\000ghi\fR.
479 .RE
480 .IP \fBX\fR 5
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,
487 .RS
488 .CS
489 \fBbinary format a3X*a3X2a3 abc def ghi\fR
490 .CE
491 will return \fBdghi\fR.
492 .RE
493 .IP \fB@\fR 5
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,
502 .RS
503 .CS
504 \fBbinary format a5@2a1@*a3@10a1 abcde f ghi j\fR
505 .CE
506 will return \fBabfdeghi\\000\\000j\fR.
507 .RE
508
509 .SH "BINARY SCAN"
510 .PP
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
516 variable.
517 .PP
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.
534 .PP
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:
540 .CS
541 \fBset signShort [binary format s1 0x8000]\fR
542 \fBbinary scan $signShort s1 val; \fI# val == 0xFFFF8000\fR
543 .CE
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 
546 value:
547 .CS
548 \fBset val [expr {$val & 0xFFFF}]; \fI# val == 0x8000\fR
549 .CE
550 .PP
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:
555 .IP \fBa\fR 5
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,
560 .RS
561 .CS
562 \fBbinary scan abcde\\000fghi a6a10 var1 var2\fR
563 .CE
564 will return \fB1\fR with the string equivalent to \fBabcde\\000\fR
565 stored in \fBvar1\fR and \fBvar2\fR left unmodified.
566 .RE
567 .IP \fBA\fR 5
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,
570 .RS
571 .CS
572 \fBbinary scan "abc efghi  \\000" A* var1\fR
573 .CE
574 will return \fB1\fR with \fBabc efghi\fR stored in \fBvar1\fR.
575 .RE
576 .IP \fBb\fR 5
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,
584 .RS
585 .CS
586 \fBbinary scan \\x07\\x87\\x05 b5b* var1 var2\fR
587 .CE
588 will return \fB2\fR with \fB11100\fR stored in \fBvar1\fR and
589 \fB1110000110100000\fR stored in \fBvar2\fR.
590 .RE
591 .IP \fBB\fR 5
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,
594 .RS
595 .CS
596 \fBbinary scan \\x70\\x87\\x05 B5B* var1 var2\fR
597 .CE
598 will return \fB2\fR with \fB01110\fR stored in \fBvar1\fR and
599 \fB1000011100000101\fR stored in \fBvar2\fR.
600 .RE
601 .IP \fBh\fR 5
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,
610 .RS
611 .CS
612 \fBbinary scan \\x07\\x86\\x05 h3h* var1 var2\fR
613 .CE
614 will return \fB2\fR with \fB706\fR stored in \fBvar1\fR and
615 \fB50\fR stored in \fBvar2\fR.
616 .RE
617 .IP \fBH\fR 5
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,
620 .RS
621 .CS
622 \fBbinary scan \\x07\\x86\\x05 H3H* var1 var2\fR
623 .CE
624 will return \fB2\fR with \fB078\fR stored in \fBvar1\fR and
625 \fB05\fR stored in \fBvar2\fR.
626 .RE
627 .IP \fBc\fR 5
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
632 example,
633 .RS
634 .CS
635 \fBbinary scan \\x07\\x86\\x05 c2c* var1 var2\fR
636 .CE
637 will return \fB2\fR with \fB7 -122\fR stored in \fBvar1\fR and \fB5\fR
638 stored in \fBvar2\fR.  Note that the integers returned are signed, but
639 they can be converted to unsigned 8-bit quantities using an expression
640 like:
641 .CS
642 \fBexpr ( $num + 0x100 ) % 0x100\fR
643 .CE
644 .RE
645 .IP \fBs\fR 5
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
651 example,
652 .RS
653 .CS
654 \fBbinary scan \\x05\\x00\\x07\\x00\\xf0\\xff s2s* var1 var2\fR
655 .CE
656 will return \fB2\fR with \fB5 7\fR stored in \fBvar1\fR and \fB-16\fR
657 stored in \fBvar2\fR.  Note that the integers returned are signed, but
658 they can be converted to unsigned 16-bit quantities using an expression
659 like:
660 .CS
661 \fBexpr ( $num + 0x10000 ) % 0x10000\fR
662 .CE
663 .RE
664 .IP \fBS\fR 5
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
667 order.  For example,
668 .RS
669 .CS
670 \fBbinary scan \\x00\\x05\\x00\\x07\\xff\\xf0 S2S* var1 var2\fR
671 .CE
672 will return \fB2\fR with \fB5 7\fR stored in \fBvar1\fR and \fB-16\fR
673 stored in \fBvar2\fR. 
674 .RE
675 .IP \fBi\fR 5
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
681 example,
682 .RS
683 .CS
684 \fBbinary scan \\x05\\x00\\x00\\x00\\x07\\x00\\x00\\x00\\xf0\\xff\\xff\\xff i2i* var1 var2\fR
685 .CE
686 will return \fB2\fR with \fB5 7\fR stored in \fBvar1\fR and \fB-16\fR
687 stored in \fBvar2\fR.  Note that the integers returned are signed and
688 cannot be represented by Tcl as unsigned values.
689 .RE
690 .IP \fBI\fR 5
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
693 order.  For example,
694 .RS
695 .CS
696 \fBbinary \\x00\\x00\\x00\\x05\\x00\\x00\\x00\\x07\\xff\\xff\\xff\\xf0 I2I* var1 var2\fR
697 .CE
698 will return \fB2\fR with \fB5 7\fR stored in \fBvar1\fR and \fB-16\fR
699 stored in \fBvar2\fR.
700 .RE
701 .IP \fBf\fR 5
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,
713 .RS
714 .CS
715 \fBbinary scan \\x3f\\xcc\\xcc\\xcd f var1\fR
716 .CE
717 will return \fB1\fR with \fB1.6000000238418579\fR stored in
718 \fBvar1\fR.
719 .RE
720 .IP \fBd\fR 5
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,
725 .RS
726 .CS
727 \fBbinary scan \\x9a\\x99\\x99\\x99\\x99\\x99\\xf9\\x3f d var1\fR
728 .CE
729 will return \fB1\fR with \fB1.6000000000000001\fR
730 stored in \fBvar1\fR.
731 .RE
732 .IP \fBx\fR 5
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,
739 .RS
740 .CS
741 \fBbinary scan \\x01\\x02\\x03\\x04 x2H* var1\fR
742 .CE
743 will return \fB1\fR with \fB0304\fR stored in \fBvar1\fR.
744 .RE
745 .IP \fBX\fR 5
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,
752 .RS
753 .CS
754 \fBbinary scan \\x01\\x02\\x03\\x04 c2XH* var1 var2\fR
755 .CE
756 will return \fB2\fR with \fB1 2\fR stored in \fBvar1\fR and \fB020304\fR
757 stored in \fBvar2\fR.
758 .RE
759 .IP \fB@\fR 5
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,
765 .RS
766 .CS
767 \fBbinary scan \\x01\\x02\\x03\\x04 c2@1H* var1 var2\fR
768 .CE
769 will return \fB2\fR with \fB1 2\fR stored in \fBvar1\fR and \fB020304\fR
770 stored in \fBvar2\fR.
771 .RE
772
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.
778
779 .SH "SEE ALSO"
780 format, scan, tclvars
781
782 .SH KEYWORDS
783 binary, format, scan