Live data from Hacker News

Understanding the power of bitwise operators

deusinmachina.net

31–40 of 48 posts

Re: Understanding the power of bitwise operators

#31
Was 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/

Re: Understanding the power of bitwise operators

#32
post #29

Earlier 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…

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.

Re: Understanding the power of bitwise operators

#33
post #32
post #29

Earlier 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 reluctant to grab "encoding letters" out of the curvy set, simply because there's nearly enough of them to make a complete binary-lettering alternative on their own. uhbDPB. That one is also frustratingly one digit missing from completion. If they were complete sets, you could treat curvy/rigid as a bit and thus have an easy and obvious system for translating between half-bytes and English orthography.

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

#34
post #8

Who 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.

What is GFX? A language?

Re: Understanding the power of bitwise operators

#35

Was 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)

Re: Understanding the power of bitwise operators

#36
There's a fairly famous bit twiddling hacks site hosted at Stanford but I find this interpretation is more accessible, and has a better breakdown, and more accessible code examples. Here's the page that's all about using the bitwise operations to query the status of the kth bit in a binary sequence:

https://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

#37

Was 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)

> If that sounds too complicated for your purposes, sorry.

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

#38

Earlier 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?

I think gp means GFX like graphic design as opposed to university computer science. At the UI layer those skills are more use than understanding bitwise operations.

Re: Understanding the power of bitwise operators

#39
post #29

Earlier 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…

That would be a trivia to have to know, otherwise it just looks like a mess of arbitrarily chosen letters. The binary patterns shown on the chosen letters do not match the actual binary patterns those letters represent. And then you don't try to do the same with 0 to 9 which makes the whole effort half-baked.

Re: Understanding the power of bitwise operators

#40

Earlier 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?

Graphics effects.
Post reply on HN