Understanding the power of bitwise operators
31–40 of 48 posts
Re: Understanding the power of bitwise operators
#32Earlier quoted context omitted.
> (e.g., Null character (�) a black diamond with white question mark in the middle). The description in the linked article is wrong, that's not a null character (U+0000) or ASCII's NUL. That black diamond symbol is U+FFFD the Unicode Replacement Character, it means "Something went wrong, so instead here is this symbol". For example if your decoder algorithm gets some gibberish and you can't or won't accept errors in…
Tangential aside we've collectively made a mistake using A-F for HEX representation. Alphabetical order seemed obvious at the time, but there's a far more literal option that's just pleasing on a visceral level. LHTIFE. The horizontal lines of each letter are literally encoding binary information. True there's no letter encoding 3 in this block style but that can either be invented or ignored. Or you can fudge the pa…
Re: Understanding the power of bitwise operators
#33Earlier quoted context omitted.
Tangential aside we've collectively made a mistake using A-F for HEX representation. Alphabetical order seemed obvious at the time, but there's a far more literal option that's just pleasing on a visceral level. LHTIFE. The horizontal lines of each letter are literally encoding binary information. True there's no letter encoding 3 in this block style but that can either be invented or ignored. Or you can fudge the pa…
The I is a bad choice since it's similar to 1, using the letter Z instead would be much better. The letter T can't be mapped to a 7-segment display either, so if that's your goal you would need to use EFGHLP.
I'm not getting sucked back into this. There comes a point when you're just staring at the alphabet letters and thinking "TF am I DOING?"
Re: Understanding the power of bitwise operators
#34Who is this article for exactly? It starts off by trying to relate to the reader by presenting the point about learning a new programming language, but then goes on to explain one of the most fundamental concepts of computing, as if the reader is a complete novice. I would imagine that nearly every person with programming experience, whether that be formal or not, would have at least some familiarity with binary repr…
Web devs? The path that goes: GFX -> HTML&CSS -> JS -> WTF! They can be great programmers in JS even but have little to no computer science behind it and more a design background.
Re: Understanding the power of bitwise operators
#35Was hoping for some magic at the end! Bit masking is one thing, but Bloom filters [0] are one of the coolest things to use when explaining why XOR is all over the place in computer science. It's behaviour is just unexpected and surprising enough to be a fun puzzle, but not too complex to make explaining it need more than 3 min and a white board. [0] https://llimllib.github.io/bloomfilter-tutorial/
The real reason for the ubiquity of XOR in computer science is that it corresponds to addition of two bits in the field GF(2). If that sounds too complicated for your purposes, sorry.
Re: Understanding the power of bitwise operators
#36https://www.techiedelight.com/bit-hacks-part-2-playing-kth-b...
Incidentally, deciphering some unknown bitwise expression is a task that ChatGPT excels at. For example, try asking it to do a stepwise breakdown and summary of:
unsigned int a, b, mask, r;
r = a ^ ((a ^ b) & mask);
Re: Understanding the power of bitwise operators
#37Was hoping for some magic at the end! Bit masking is one thing, but Bloom filters [0] are one of the coolest things to use when explaining why XOR is all over the place in computer science. It's behaviour is just unexpected and surprising enough to be a fun puzzle, but not too complex to make explaining it need more than 3 min and a white board. [0] https://llimllib.github.io/bloomfilter-tutorial/
This is a baffling comment, since Bloom filters don't use XOR. Indeed, the link you provide doesn't mention it. I honestly don't know what role XOR would play in an explanation of Bloom filters. The real reason for the ubiquity of XOR in computer science is that it corresponds to addition of two bits in the field GF(2). If that sounds too complicated for your purposes, sorry. https://en.wikipedia.org/wiki/GF(2)
Ehhh, GF(2) and even GF(5) are actually pretty easy to describe.
GF(2) is arithmetic modulo 2.
0+0 == 0
0+1 == 1
1+0 == 1
1+1 == 10, except we can only carry one bit in GF(2). Like an odometer, we can only keep the bottom bit, so the "1" drops off. 1+1 == 0.
Hey look, its XOR. The end.
----------
A "Field" in Abstract mathematics is simply a number-system that has add, additive-inverse (aka: subtraction), multiply, and multiply-inverse (aka: division). Note that "subtraction" and "division" are just simplifications of the concept, to be a true inverse, all inputs and outputs (domains-and-ranges) must be in the field.
So I proved that XOR is GF(2)'s addition. Funny note, 1 is also -1 (negative 1), aka the additive inverse of 1. And it turns out that XOR is _also_ the additive inverse (aka: subtraction). You see, -1 + 1 == 0, which happens to be 1+1 in GF(2). Ain't modulo math fun?
-----------
Multiplication is just AND btw.
0 * 0 == 0
0 * 1 == 0
1 * 0 == 0
1 * 1 == 1
The multiplicative inverse of 1 is... 1. That is, 1 * 1 equals 1. This one is a bit of a tautology, but it matches the technical definition of multiplicative-inverses (aka: division). This is why I prefer GF(5), because we get a less-trivial multiplicative-inverse.
----------
GF(5) is how I prefer to teach Galois fields. GF(2) and GF(3) are too simple. GF(5) is complex enough that the student actually has to learn Galois fields to understand it, but its simple enough that you can probably teach it to someone within 20 minutes.
Re: Understanding the power of bitwise operators
#38Earlier quoted context omitted.
Web devs? The path that goes: GFX -> HTML&CSS -> JS -> WTF! They can be great programmers in JS even but have little to no computer science behind it and more a design background.
What is GFX? A language?
Re: Understanding the power of bitwise operators
#39Earlier quoted context omitted.
> (e.g., Null character (�) a black diamond with white question mark in the middle). The description in the linked article is wrong, that's not a null character (U+0000) or ASCII's NUL. That black diamond symbol is U+FFFD the Unicode Replacement Character, it means "Something went wrong, so instead here is this symbol". For example if your decoder algorithm gets some gibberish and you can't or won't accept errors in…
Tangential aside we've collectively made a mistake using A-F for HEX representation. Alphabetical order seemed obvious at the time, but there's a far more literal option that's just pleasing on a visceral level. LHTIFE. The horizontal lines of each letter are literally encoding binary information. True there's no letter encoding 3 in this block style but that can either be invented or ignored. Or you can fudge the pa…