in reply to Re: Re: Can you spot the problem?
in thread Can you spot the problem?
... the opening post attempts to be clever, but instead it does something that doesn't even make sense...
It make sense if you understand a lower-level idiom. To be fair, I left off the thread of discussion that led up to something close to that particular snippet.
The problem, at the level of that statement, is to determine if any one of the octet numbers exceeds 255. You can compare the numbers one by one, or you can take advantage of knowing that 255 == 0xFF, and that if any one of the octet numbers is larger than that, the OR of all the numbers will have bits set above 0xFF, and will hence be greater than 255 (and conversly, a valid quad will OR to less than 256). At a raw instruction level, doing three ORs and one test/branch is faster than doing four individual test/branches if the majority of the IP addresses are going to be valid. This works well in assembler, and in C (which is a limited number of steps above assembler). If you haven't played at that level, the idiom may seem strange. And, unless performance really, really matters, it's not a technique that I'd use in production Perl. But for purposes of the puzzle, it's great, since it's so misleading.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: Re: Can you spot the problem?
by ambrus (Abbot) on Mar 06, 2004 at 19:53 UTC |