4 ms·
Bit Level Manipulation
- ColinWright 14y agoSerious question: How many people here on HN find things at this level useful? I'm always intrigued to find out how many working programmers don't know this sort of thing. I might start a poll on it ...
- ColinWright 14y agoI did start a poll on it: https://news.ycombinator.com/item?id=5506656 https://news.ycombinator.com/item?id=5506656
- huhtenberg 14y agoIt's truly depressing to see this submission sitting at 20+ upvotes, on HN of all places.
- mburst 14y agoJust because you know something doesn't mean everyone else does. This is one of those mentalities that prevents people from asking questions and learning new things. You're sitting in a classroom and the professor goes over a challenging topic but you look around and it seems everyone else understands it. So to save yourself from looking stupid you don't ask a question. If you've had a formal education in programming then you've probably at least heard of bitwise operators. If not then I could definitely see these things not coming up. Either way I find compiler optimizations neat so I figured I'd make a post and share about some of the basic ones.
- huhtenberg 14y agoAs I said, it's depressing to see this sort of topic being of an interest to a wider HN audience. It's not the topic that's bad, it's the audience composition that's disappointing.
- jared314 14y agoI have always wondered why I was taught binary as if they were arrays, but programming languages never allowed me to use bits like arrays. It's always masking and shifting uint16_t or int32_t, instead of what I really want, "result = bits[3] xor bits2[3]".
- jonsen 14y agoI'm unable to find a reference, but I'm pretty sure you could do that in PL/I.
- simarpreet007 14y agoIt's never bad to post something that might seem very trivial at first. I learnt the trick of checking an odd or even with this post. Thanks OP!