Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
olback116912yCause it's useful...
Loooooong time ago I had to work with a script which stored user permissions as defined constants with numeric values. Something along the lines of:
This was fuckint retarded and counterintuitive since you had to pick successive values in regards to the power of 2 val. Wht made it better is that the app was fucking huge. And there were a fuckload of users(logistics company) and because most of these fucktards were not actual engineers then no one understood why our 32 bit server 64bit server mashup was creating weird problems all over the place.
Php has defined boolean logic and values...i don't see why people would just say fuck it and do things from php3
C0D4594742y@olback In 14 years of PHP’n, I’ve only encounter an actual use for them (in php) in scary code and logic.
I do use them I mysql though but even then it’s purely for null safe comparisons.
@AleCx04 that must have been a thing some time ago, I had a similar experience where the dev defined permissions using binary, each role was the next increment, shit got messy real quick.
olback116912yOne use case is converting chars to upper/lower case.
'A' | 0x20 // 'a'
'a' | 0x20 // 'a'
'B' & 0xcf // 'B'
'b' & 0xcf // 'b'
Another use case: Repacking an 32-bit int to 4 8bit ones. I needed this in my current project. https://github.com/shopper-ink/...
These examples are probably not very useful in PHP though as PHP probably has built in functions for converting to upper/lower case letters.
I also think you should understand bit shifting if you consider yourself a programmer since it's a fundamental part of how computers work. Just my opinion though.
@C0D4 @AleCx04 I worked at a place that generated error codes that way, really it was a bit wise call stack, it was still a mess because “Int64 CStack” was required to be the first parameter of every function, you adjusted it in the first few lines and returned the value on caught error. Why they didn’t use the built in call stack is beyond me.
@olback no one said anything in here about not understanding bit shifting.
The topic was their usefulness inside php programming as it stands for web development.
Don't claim the whole "if you consider yourself a programmer" rethoric if you are not going to provide an example and then give a wiki example of bit shifting on something that is not the relevant topic at hand.
@C0D4 its a very interesting way of doing things and I am willing to bet that the devs that used to do this sort of deal were very old school. It sure was a learning experience when I first saw it. Normally I would let someone else deal with it :V but that time it was all on yo boi right here.
@bkwilliams that one is definitely a strange one. Could it be that that was coming from an linux dev? That example is fairly reminiscent of how they would generate custom error messages before. I have no experience on that one(linux system development)though so I cannot say for sure.
Idk. I try to write code that is actually readable and leave bitwise operations and other flashy shit for code golf.
Unless it makes sense, of course.
Root672842yI have rarely ever found a use for bitwise math in backend dev. Its useful for optimizing complex math, but that's rarely ever needed in web dev.
The last time I used bitwise math was picking apart Epson status codes (as they use bitflags). 12 bitflags and I was done. It was disappointing.
The second to loast time I needed to use bitwise ops was on the frontend as part of a memory slider that snapped to powers of two. As the code needed to run thirty to sixty times a second, optimizing and memoizing it was actually needed -- and fun! I wrote the entire thing using bit ops, with plenty of comments describing exactly what each unintuitive and confusing mess of symbols was doing and why. The end result was very fast 😊
Before that, all of the bitwise math I used was in networking, game development, and similar environs.