Live data from Hacker News

Understanding the power of bitwise operators

deusinmachina.net

21–30 of 48 posts

Re: Understanding the power of bitwise operators

#21

I like introducing people to new concepts, and I will assume this entry is for non-technologists. This is an excellent start. If I may suggest, stop insulting your readers (e.g., several places implying reader does or does not do something 'normally', or not know something). In cases where an error is well known, describe the error so it is understood you are using it as an example, and not an actual error (e.g., Nul…

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

[dead]

Re: Understanding the power of bitwise operators

#22
post #12
post #6

Is it an autocorrect issue or the writer only-heard-never-read that the "^" character is called a “carrot”?

The "^" character is correctly named the "caret".

Common: hat; control; uparrow; caret; official name: circumflex. Rare: xor sign, chevron; to the (‘to the power of’); fang; pointer (in Pascal).

(http://catb.org/jargon/html/A/ASCII.html)

Re: Understanding the power of bitwise operators

#23
> While at first, they might seem obscure, unhelpful, or tools for people who write in low level programming languages, they do serve a purpose.

Firstly, no one says that bitwise operators don't serve a purpose. Secondly, this is an interesting way to start an article that then goes on to explain how useful bitwise operators are for low level programming.

Re: Understanding the power of bitwise operators

#24
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.

Re: Understanding the power of bitwise operators

#25

OT but his mention of the calculator reminded me of discovering just yesterday that the built in Mac calculator has a Programmer mode (apparently Windows too) for hex, etc. I’d been using the RPN/scientific mode for ever but never new about Programmer mode. I’m actually doing a fair amount of hex conversions and bit fiddling these days (webassembly bytecode) so it was actually something useful.

And don't miss that clicking the displayed bits will flip them. Can be handy at times, debugging flags for example.

Re: Understanding the power of bitwise operators

#26
Bitwise operators are the beginners introduction to SIMD programming.

A 64 bit register doing XOR is really 64x parallel XOR happening in parallel each of size 1 bit.

A shift, rotate are just fancy movement operators and exist in the SIMD space.

Good bitwise programming IMO requires a full embrace of this parallel mindset. See the Chess Programming Wiki for all sorts of things that 64x parallel bits can represent.

In particular, a 8x8 chessboard maps well to 64 bits.

-------

No really. Do remember that one of the OG SIMD computers, the CM2 (connection machine 2) was a 1-bit core but SIMD across thousands of cores (bits). And a lot of research and understanding of modern parallel concepts comes from the Connection Machine.

Re: Understanding the power of bitwise operators

#27
post #18
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…

> would have at least some familiarity with binary representation and bitwise operations. There's a whole generation of programmers that aren't interested in, and don't need , "low level" bitwise operations. I would claim that's a "good thing", since it means they're letting someone else do the "boring stuff" by using libraries, allowing them to spend more time solving higher level problems. When I was going to schoo…

> There's a whole generation of programmers that aren't interested in, and don't need, "low level" bitwise operations.

But it's worth understanding them even if you never need to use them. Much like understanding how a computer works at a low level, that kind of knowledge helps contextualize higher-level things and puts additional tools in your toolbox.

Re: Understanding the power of bitwise operators

#28

I like introducing people to new concepts, and I will assume this entry is for non-technologists. This is an excellent start. If I may suggest, stop insulting your readers (e.g., several places implying reader does or does not do something 'normally', or not know something). In cases where an error is well known, describe the error so it is understood you are using it as an example, and not an actual error (e.g., Nul…

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

[deleted]

Re: Understanding the power of bitwise operators

#29

I like introducing people to new concepts, and I will assume this entry is for non-technologists. This is an excellent start. If I may suggest, stop insulting your readers (e.g., several places implying reader does or does not do something 'normally', or not know something). In cases where an error is well known, describe the error so it is understood you are using it as an example, and not an actual error (e.g., Nul…

> (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 pattern slightly with a diagonal such as z or a curved lower case such as b. It would have mapped so cleanly to 7 seg type displays. Even the name "HEX" is 2/3rds of the way to being self descriptive. A perfect little numeral grouping of chars.

Re: Understanding the power of bitwise operators

#30

I was just doing some bit shifting yesterday. I wanted to pass a drawing function a Uint16 that would represent a 4x4 black and white pixel pattern. It was a little hack to create early MacOS-like pixel patterns in SDL. SDL has primitives for line and rectangle drawing with solid colors but little else. So I wrote some straight C, some nested for loops for row/column of the area to be patterned . I used row % 4, colu…

Try the generalized problem of in-place arbitrary 2x2 matrix transforms.
Post reply on HN