This long article is a great example of why I believe GPT has a strong future. The article spends several pages to explain hexadecimal, bases, etc. Probably some fraction of the audience already knows that. In that case, the article should automatically adapt and skip that section. Some people will react negatively to the mathematical formulation, preferring the intuitive section that follows instead. But this is a s…
Demystifying bitwise operations, a gentle C tutorial
21–30 of 95 posts
Re: Demystifying bitwise operations, a gentle C tutorial
#22I’ve found significant code in c/c++ where bitwise operations are done for things like division etc by shifting a certain way. I Can imagine in the past, this was “faster”, yet clang/gcc can emit the same by just writing a basic A/B function. Seems the win goes to readability by reducing some of these old school hacks. What say you, greybeards ?
But yes, fast inverse sqrt is obsolete.
Re: Demystifying bitwise operations, a gentle C tutorial
#23While it's based on C, a large chunk of the content is simply a great introduction to number representations in other bases such as binary and hexadecimal etc. Fundamental knowledge and very well explained, and a few insights I've not seen before.
yes? no? hard to say
The number of times I've needed this knowledge during all years of formal education and then years of work would be probably around 3.
Then I started working with C and close to hardware and it became something that I need everyday.
It's feels like bit proficiency is only useful in some very specific domains.
Thought: is HTTP foundational knowledge nowadays? after all whole world is built on it
if not, when will it become?
Re: Demystifying bitwise operations, a gentle C tutorial
#24This long article is a great example of why I believe GPT has a strong future. The article spends several pages to explain hexadecimal, bases, etc. Probably some fraction of the audience already knows that. In that case, the article should automatically adapt and skip that section. Some people will react negatively to the mathematical formulation, preferring the intuitive section that follows instead. But this is a s…
In all seriousness though, this blogpost does exactly what it intends to do. Demistify bitwise operations and you can't skip the math.
Re: Demystifying bitwise operations, a gentle C tutorial
#25This long article is a great example of why I believe GPT has a strong future. The article spends several pages to explain hexadecimal, bases, etc. Probably some fraction of the audience already knows that. In that case, the article should automatically adapt and skip that section. Some people will react negatively to the mathematical formulation, preferring the intuitive section that follows instead. But this is a s…
Although I do agree that repeating the basics on every post is cumbersome, it seems adequate for this post.
Re: Demystifying bitwise operations, a gentle C tutorial
#26I’ve found significant code in c/c++ where bitwise operations are done for things like division etc by shifting a certain way. I Can imagine in the past, this was “faster”, yet clang/gcc can emit the same by just writing a basic A/B function. Seems the win goes to readability by reducing some of these old school hacks. What say you, greybeards ?
Similarly, a fast divisibility test (we’ll assume we’re dividing n by some odd prime p):
1. Shift the bits of p right so that there is a 1 in the last position.
2. If n = p then p∣n, if n p then p∤n, otherwise continue.
3. Subtract p and go back to step 1.
(One of my ADD habits during meetings is to find the prime factors phone numbers or anything else very long. I do something similar with the numbers in decimal, but for this, I’ll subtract multiples of the potential divisor to get 0s at the end of the number in decimal. I remember co-workers puzzling over a piece of paper with my notes I left behind in a conference room trying to figure out what the numbers represented and how the process worked.)
Re: Demystifying bitwise operations, a gentle C tutorial
#27I suspect that this is because both the table and the code used were sourced from Wikipedia, and they correspond to different Gray codes. The table is for the BRGC, but the implementation isn't.
Re: Demystifying bitwise operations, a gentle C tutorial
#28This long article is a great example of why I believe GPT has a strong future. The article spends several pages to explain hexadecimal, bases, etc. Probably some fraction of the audience already knows that. In that case, the article should automatically adapt and skip that section. Some people will react negatively to the mathematical formulation, preferring the intuitive section that follows instead. But this is a s…
Re: Demystifying bitwise operations, a gentle C tutorial
#29I’ve found significant code in c/c++ where bitwise operations are done for things like division etc by shifting a certain way. I Can imagine in the past, this was “faster”, yet clang/gcc can emit the same by just writing a basic A/B function. Seems the win goes to readability by reducing some of these old school hacks. What say you, greybeards ?
For example, see the article and discussion on Bitwise Division from two days ago: https://news.ycombinator.com/item?id=34981027
Re: Demystifying bitwise operations, a gentle C tutorial
#30I thought this was going to be ridiculous but it's actually a really good. It's clear enough that you could extend it down to showing how logic gates work. The only thing missing is a little endian discussion; it assumes big endian (network byte order), and that may be confusing for all those x86 users out there.
> that may be confusing for all those x86 users out there. It’s pretty much every user these days - even most MIPS based network oriented devices run LE. BE lost many years ago.