Cure
User
Apr 20, 2000, 4:49 PM
Post #6 of 10
(13763 views)

Re: "bits and bits" !~ /scambled eggs for brain/;
[In reply to]

Can't Post


Hi You go out of your way to produce fivedigit strings for $thiskey, and $binary is a fivedigit string, so you seem to be doing a *stringwise* AND. But the code is doing a *bitwise* AND, and the result happens  purely by chance!  to look like the result of a stringwise AND, except for the case of '01000'. The clue is that $truth is being printed as an integer, not as a fivedigit string. When I stringify $thiskey explicitly (usefully doublequoting a simple variable!): my $truth = $binary + "$thiskey"; the 104 becomes 00000 (and all the other TRUTHs are fivedigit strings, as expected). The reason I am baffled is this: print "Padded key : $thiskey\n"; # In the line above, $thiskey is a fivedigit string. my $truth = $binary & $thiskey; # In the line above, $binary is a fivedigit string. print "The TRUTH is $truth\t ($binary and $thiskey )\n"; # In the line above, $thiskey is a fivedigit string. Why does $thiskey become an integer, which 'integrifies' the value of $binary, for the duration of the conjuction statement, but is still a string after it??? In binary, 00110 is 0001101110 01000 is 1111101000 The bitwise AND is 0001101000 which is 104 Because if you do the same conversions and bitwise arithmetic as I did above, you will get BY PURE COINCIDENCE a binary result which, when converted to decimal, looks the same as a stringwise AND.
