Re: question on funny behaviour of binary scan
From: Bruce Hartweg (bruce-news_at_hartweg.us)
Date: 02/11/05
- Next message: Lord Floyd: "Re: Creating a database with MySQLTcl"
- Previous message: 04642920123-0001_at_t-online.de: "question on funny behaviour of binary scan"
- In reply to: 04642920123-0001_at_t-online.de: "question on funny behaviour of binary scan"
- Next in thread: 04642920123-0001_at_t-online.de: "Re: question on funny behaviour of binary scan"
- Reply: 04642920123-0001_at_t-online.de: "Re: question on funny behaviour of binary scan"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 11 Feb 2005 09:15:19 -0600
04642920123-0001@t-online.de wrote:
> Hi Tclers,
> ,
> i've run into trouble using binary scan:
>
> % binary scan "\x55" BBBBBBBB a b c d e f g h i
> 1
> % set a
> 0
> % set b
> can't read "b": no such variable
>
> % binary scan "\x55\x55" BBBBBBBB a b c d e f g h i
> 2
> % set a
> 0
> % set b
> 0
> % set c
> can't read "c": no such variable
>
> Now a is OK, b should have been 1 this look like scan
> took the next byte
>
> % binary scan "\x55\xaa" B4B* a b
> 2
> % set a
> 0101
> % set b
> 10101010
>
> a is OK but b should be 12 Bits ie: 010110101010
> and not 8 Bits?
>
> tested versions: tcl-8.4.2, tcl-8.4.6
> there seems to be no bug listed for
> the binary command at sourceforge.
>
it's not a bug, it's a feature!
seriously, that is how it is docum,ented to work - check out
http://www.tcl.tk/man/tcl8.4/TclCmd/binary.htm#M27
which has: (emphasis mine)
b
The data is turned into a string of count binary digits in low-to-high order
represented as a sequence of ``1'' and ``0'' characters. The data bytes are
scanned in first to last order with the bits being taken in low-to-high order
within each byte.
**********************************************************
***** Any extra bits in the last byte are ignored. ******
**********************************************************
If count is *, then all of the remaining bits in string will be scanned.
If count is omitted, then one bit will be scanned. For example,
binary scan \x07\x87\x05 b5b* var1 var2
will return 2 with 11100 stored in var1 and 1110000110100000 stored in var2.
B
This form is the same as b, except the bits are taken in high-to-low order
within each byte. For example,
binary scan \x70\x87\x05 B5B* var1 var2
will return 2 with 01110 stored in var1 and 1000011100000101 stored in var2.
Bruce
- Next message: Lord Floyd: "Re: Creating a database with MySQLTcl"
- Previous message: 04642920123-0001_at_t-online.de: "question on funny behaviour of binary scan"
- In reply to: 04642920123-0001_at_t-online.de: "question on funny behaviour of binary scan"
- Next in thread: 04642920123-0001_at_t-online.de: "Re: question on funny behaviour of binary scan"
- Reply: 04642920123-0001_at_t-online.de: "Re: question on funny behaviour of binary scan"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|