- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Simple. I don't. That's what URLs are for.
Don't be a haero. Use URLs.
Admin
lol. Some applications need to work on IPs you know, as data and all ;)
Admin
These values would apply to BCD encoding. Maurits also pointed out that 10010 is (hex) 0x12. However, the author was using the standard binary values that redtetrahedron provided.
Admin
Yeah, the string parameter is bad, and the documentation could be improved ever so slightly, but on the whole this code is okay. The WTF is not in the code - it's the existence of the function itself that is the WTF. Apparently we're dealing with a programmer whose brain shorts when he sees things like ‘$val |= $mask’. Apparently he didn't just not know what this meant, but even after figuring it out (presumably a process laborious enough to warrant the function under discussion) he still cannot remember it. I weep for him and his colleagues.
Admin
However, based on the signature of the function in this example, I'm betting that's not the answer here.
Admin
You've gotta be kidding.
Admin
That's not a bug in the function. That's a problem with the implementation of automatic type conversions in PHP. That's like saying that if I write a function that says "return a+b" to add two numbers together, my code has a bug because if the user passes in "foobar" for "a" it will not give meaningful results. Or are you insisting that every PHP function must completely re-implement all the type conversions?
Admin
It's fair to ask why the programmer found a need to do bit-twiddling. But it's not fair to ridicule him for doing bit-twiddling before you've heard the answer. Maybe he has a very sensible reason. Hey, maybe he's implementing a calculator that has AND and OR functions and it's an explicit requirement.
Admin
A couple of comments:
For the record, bit numbers are usually counted from 0 (ie: The bit with the value '8' is bit 3, not 4). This way, the value of a bit is given by 2^bitnum.
Why wasn't I invited to the meeting where it was decided that 'down' is a synonym for 'false'?
Admin
This code is a bit strange, but I don't see anything particularly WTF-worthy in it.
Admin
Admin
If I set only bit 4 of a byte, I get 00010000, or 16 decimal. The hardware devices I use call the rightmost bit "bit 0." It looks like whoever wrote that PHP started from "bit 1," which strikes me as odd, but is probably not unheard of.
These bit numbers most definitely are in decimal, though. I've never seen anyone call the leftmost bit of a 16-bit number "bit F," for example... it's bit 15. (I suppose this is one of the many things about which I can say, "no one would ever X, except maybe a poster from The Daily WTF.")
Incidentally, I don't consider the code originally posted that much of a WTF, unless it has some kind of bug that I don't see. (I know nothing of PHP).
The function makes heroic efforts to deal with inconsistent input formats. That doesn't seem like the sort of thing that ought to require an apology; the author of this code was just engaging in defensive programming.
Admin
Admin
As Haskell is all moderny and stuff and according to your comment, wouldn't that be because operators are wrapped in functions in Haskell - or something equivalent ?
Admin
Some people I won't name (yet!) used an int field of booleans for security access rights - read, write, admin. Spot the extra deliberate mistake? :-)
Admin
I think those people are commonly referred to as, "the inventors of Unix". I think Unix file permissions are routinely packed as bit-flags in an int.
Admin
I'll say a couple things about what Haskell does, and you can decide if it's helpful for your understanding or not. (Disclaimer: the code below isn't compiled, so it may not be legal. But the idea is there.)
Suppose I have a function compute that takes a binary function, applies it to 1 and 2, then returns the result:
What you can't do is pass "+" to it, because "+" is an operator, not a function:
(-- marks a comment)
Now, I can write a function "add" that does what it says, then use that to call "compute":
but I can also get a function from an operator really easily, by using "(+)":
(Incidentally, you can also fix one operand. "(+)" gives a function that takes two ints and gives their sum; "(+8)" gives a function that takes one int and returns that plus 8. Haskell calls this a "section.")
You can also go the other way; by putting backticks around a binary function, you can use it as a binary operator:
Admin
Here's to hoping that I'll never have to use Haskell. Reminds me too much of Perl - a language seemingly designed by an Egyptologist.
Admin
We're looking forward to reading your code in an upcoming TDWTF!
Admin
I like how he clearly used his own function to run the values he mentions in the comments, instead of documenting how it should really work!
Admin
Admin
Sorry, but no. neither gmp_setbit in PHP nor the underlying mpz_setbit function in the GMP library work with a bit mask. Actually the example given in the reference you provided contradicts your statement. For the really interested take a look at PHP source code line 1453 (implementation of gmp_setbit) and mpz_setbit from the GMP lib
In my opinion this is also the WTF...