Time was when I would hack together a C program to use bitwise
operators to pick off individual bits that were of interest. But for
all sorts of reasons I thought it would be sensible to write some
general purpose code that could easily be configured for different
kinds of information.
So I set about using `binary scan' to convert the byte stream into a
list of 1s and 0s, with a little algorithm to compute the index number
of any given variable in this list. But I started getting unexpected
results. So I did a some experimenting and decided I don't
understand the proper use of the binary conversion types. For
instance:
% binary scan " z" "B16" junk; #chosen because the bit patterns are distinctive
1
% puts $junk
0010000001111010
% binary scan " z" "b16" $junk
1
% puts $junk
0010000001111010 - so no difference there, lets add another character
% binary scan " z" "b24" junk
1
% puts $junk
000001000000010001011110
% binary scan " z" "B24" junk
1
% puts $junk
001000000010000001111010 - bit patterns are reversed.
% binary scan " z " "B32" junk; # add another character
1
% puts $junk
00100000001000000111101000100000
% binary scan " Z " "b32" junk
1
% puts $junk
00000100000001000101101000000100 - still reversed
I can imagine that there is a sensible explanation for this, but I
can't for the life of me see what it is. And when I have a few
hundred bytes to convert I really can't tell what's going on.
But I bet someone can ;-)
--
Steve Blinkhorn <st...@prd.co.uk>
[lead-in snipped]
>% binary scan " z" "B16" junk; #chosen because the bit patterns are distinctive
>1
>% puts $junk
>0010000001111010
>% binary scan " z" "b16" $junk
>1
>% puts $junk
>0010000001111010 - so no difference there, lets add another character
This surprises me - I would have expected a "reverse" pattern.
>% binary scan " z" "b24" junk
>1
>% puts $junk
>000001000000010001011110
>% binary scan " z" "B24" junk
>1
>% puts $junk
>001000000010000001111010 - bit patterns are reversed.
This would meet my expectations,
>% binary scan " z " "B32" junk; # add another character
>1
>% puts $junk
>00100000001000000111101000100000
>% binary scan " Z " "b32" junk
>1
>% puts $junk
>00000100000001000101101000000100 - still reversed
and so would this. What do you mean by 'still reversed'?
Could it be, you tried to shoot yourself in the foot by using a 'Z' (a
*capital* z) in your last example? :)
Please repost if I answered the wrong question - I'm not quite sure
what your problem is.
Best regards
Helmut Giese
>On 13 Mar 2003 18:17:54 GMT, st...@sole.prd.co.uk (Steve Blinkhorn)
>wrote:
>
> [lead-in snipped]
>
>>% binary scan " z" "B16" junk; #chosen because the bit patterns are distinctive
>>1
>>% puts $junk
>>0010000001111010
>>% binary scan " z" "b16" $junk
$junk ???
>>1
>>% puts $junk
>>0010000001111010 - so no difference there, lets add another character
>This surprises me - I would have expected a "reverse" pattern.
No surprise here after all. After a little playing around showed that
[binary scan] does work for me as expected, I looked again and, well,
see above.
Helmut Giese