Skip to content
Tcl Source Code History Of Ticket 1663473
Login

History Of Ticket 1663473

Artifacts Associated With Ticket 1663473

  1. Ticket change [ba0ef10b1d] (rid 129254) by lvirden on 2007-02-19 13:35:59:

    1. assignee initialized to: "dkf"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      From the man page for binary scan:
      
           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.
      
      
      Perhaps I don't understand the meaning of the phrase "remaining bits in string".
      
      It seems, to me, that this is a 24 bit string:
       % puts [string length  \x07\x87\x05 ]
       3
      and as far as I know, on a sparc solaris machine, 3 bytes, times 8 bits per byte, should equal 24 bits.
      
       % binary scan \x07\x87\x05 b5b* var1 var2
      2
       % puts $var1
      11100
       % puts $var2
      1110000110100000
      % puts [string length $var1$var2]
      21
      
      Notice that 3 bits are missing. They are 000 from the first byte of the 3 bytes...
      
    4. foundin initialized to: "obsolete: 8.5a6"
    5. is_private initialized to: "0"
    6. priority initialized to: "5 Medium"
    7. resolution initialized to: "None"
    8. status initialized to: "Open"
    9. submitter initialized to: "lvirden"
    10. subsystem initialized to: "16. Commands A-H"
    11. title initialized to: "binary scan seems to be losing bits"
    12. type initialized to: "Bug"
  2. Ticket change [f4502147eb] (rid 129889) by dkf on 2007-02-20 05:31:04:

    1. assignee changed to: "hobbs"
    2. subsystem changed to: "12. ByteArray Object"
  3. Ticket change [60a4d92863] (rid 116034) by hobbs on 2007-02-20 06:59:23:

    1. closedate changed to: "2007-02-19T23:59:23"
    2. closer changed to: "hobbs"
    3. icomment:
      Logged In: YES 
      user_id=72656
      Originator: NO
      
      Using tkcon:
      
      (Tcl) 51 % binary scan \x07\x87\x05 b5b* var1 var2
      2
      (Tcl) 52 % binary scan \x07\x87\x05 b* var3
      1
      (Tcl) 53 % dump var var*
      set ::var1 11100
      set ::var2 1110000110100000
      set ::var3 111000001110000110100000
      
      You see that the missing 000 would be the first part of var2 - IOW, extraneous bits.  I don't see a bug here.  The values are correct, it is just that Tcl does format with all the preceding 0s.
      
      
    4. login: "hobbs"
    5. mimetype: "text/plain"
    6. resolution changed to: "Invalid"
    7. status changed to: "Closed"
    8. username: "hobbs"
  4. Ticket change [69781b949e] (rid 103260) by lvirden on 2007-02-20 18:30:58:

    1. icomment:
      Logged In: YES 
      user_id=15949
      Originator: YES
      
      binary scan \xff\xff\xff var3 var4
      
      shouldn't be any leading zeros here, right? however,
      puts $var3
      11111
      which is what I would expect
      puts $var4
      1111111111111111
      string length $var4
      16
      Still only seeing 21 of the 24 bits. Shouldn't there be 19 bits here?
      
      
    2. login: "lvirden"
    3. mimetype: "text/plain"
    4. resolution changed to: "Rejected"
    5. username: "lvirden"
  5. Ticket change [d588692212] (rid 123640) by msofer on 2007-02-20 20:09:20:

    1. icomment:
      Logged In: YES 
      user_id=148712
      Originator: NO
      
      The way I understand the last example 
       binary scan \xff\xff\xff b5b* var3 var4
      according to the docs is:
      
      (1) first read 5 bits, ie, the first 5 bits of one byte. The 5 bits are put into var3, the remaining 3 bits are discarded ("Any extra bits in the last byte are ignored."). The first byte is now done with.
      
      (2) now read all the rest.
      
      A slightly different experiment seems to confirm this interpretation (a final answer requires source diving, which I may do later):
      
      % binary scan \xff\xff\xff b8b* var3 var4
      2
      % string length $var3
      8
      % string length $var4
      16
      % binary scan \xff\xff\xff b9b* var3 var4
      2
      % string length $var3
      9
      % string length $var4
      8
      
      
      I do confess that this interpretation has been arrived at *after* seeing the example; the docs may need to be improved?
      
      
    2. login: "msofer"
    3. mimetype: "text/plain"
    4. username: "msofer"
  6. Ticket change [925d31ac25] (rid 120752) by lvirden on 2007-02-20 20:28:45:

    1. icomment:
      Logged In: YES 
      user_id=15949
      Originator: YES
      
      updated docs would seem to be useful.
      
      This does mean that one cannot scan a byte into two or more variables. One has to scan the byte in, then split the string up via normal string functions.
      
      That's too bad - it would have been nice to have had a format that would allow the person to split the byte up into several pieces - getting at the various status bits of a control register or
      whatever.
      
      
    2. login: "lvirden"
    3. mimetype: "text/plain"
    4. username: "lvirden"
  7. Ticket change [17bb5ed186] (rid 122543) by dkf on 2007-02-20 21:40:27:

    1. icomment:
      Logged In: YES 
      user_id=79902
      Originator: NO
      
      The problem is that reading at the bit level across multiple variables would make the code to do bulk uses of [binary scan] much harder since you'd have to allow for someone reading one bit and then 100kB of 32-bit words, all offset by one bit, even though this is a vanishingly rare case.
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"