Live data from Hacker News

Show HN: HN Avatars in 357 bytes

news.ycombinator.com

171–180 of 536 posts

Re: Show HN: HN Avatars in 357 bytes

#174

Earlier quoted context omitted.

I think before you can understand binary operators, you’ll need to understand binary itself and how to convert it to and from decimal. This crash course computer science video may help: https://youtu.be/1GSjbWt0c9M In fact the whole course might be useful!

I understand the conversion and representation - i guess I just dont understand the intent behind the usage of these operators. Without stepping through each line in a debugger I literally have no idea what the ungolfed version of the main post is doing, or why its doing it - and this seems to be typical of my experience with bitwise operators. But I will definitely have a look at the references you have given. Hopef…

There's many reasons for bitwise operators to exist.

For instance it's extremely easy, when looking at the binary representation of a number to check the correct end of the byte and determine if a number is odd or even.

You can use bitwise operators to bit shift and check if a value is over a certain amount but seeing if there is any value after a bit shift.

there's tonnes of real world applications:

* Bit fields (flags)

As they're the most efficient way of representing something whose state is defined by several "yes or no" properties. ACLs are a good example; if you have let's say 4 discrete permissions (read, write, execute, change policy), it's better to store this in 1 byte rather than waste 4. These can be mapped to enumeration types in many languages for added convenience.

* Communication over ports/sockets

Always involves checksums, parity, stop bits, flow control algorithms, and so on, which usually depend on the logic values of individual bytes as opposed to numeric values, since the medium may only be capable of transmitting one bit at a time.

* Compression, Encryption

Both of these are heavily dependent on bitwise algorithms. Look at the deflate algorithm for an example - everything is in bits, not bytes.

* Finite State Machines I'm speaking primarily of the kind embedded in some piece of hardware, although they can be found in software too. These are combinatorial in nature - they might literally be getting "compiled" down to a bunch of logic gates, so they have to be expressed as AND, OR, NOT, etc.

* Graphics

There's hardly enough space here to get into every area where these operators are used in graphics programming. XOR (or ^) is particularly interesting here because applying the same input a second time will undo the first. Older GUIs used to rely on this for selection highlighting and other overlays, in order to eliminate the need for costly redraws. They're still useful in slow graphics protocols (i.e. remote desktop).

Re: Show HN: HN Avatars in 357 bytes

#180

Hah! I got a really cool little icon that looks almost like the cassette tape pirate logo of Piratbyrån back in the day. I have old t-shirts with that logo. MAKE. THIS. PERMANENT! On the functional side, this really helps you see who is who in a long threaded discussion. Your eye is much quicker at following the little color icons than their names.

It should be fairly straightforward to turn this into a browser addon, give users a choice and offload the people behind HN.

Could we just add it to HN Special? https://github.com/gabrielecirulli/hn-special
Post reply on HN