Live data from Hacker News

Do you know your bitwise operators?

quaxio.com

11–20 of 32 posts

Re: Do you know your bitwise operators?

#11
post #9
post #8

Earlier quoted context omitted.

It appears to have a limited JS validator to prevent you from using anything other than the limited operators it allows.

It really doesn't like having anything after "return" except a single value or variable.

That's not it. For example, it accepts "return x|x&x;" . The restriction is that only a handful of Javascript operations are allowed. Anything else gives a hard-to-understand error message.

Re: Do you know your bitwise operators?

#13
post #4

This is stated to be a puzzle. But, when does this actually get used? Are there use cases of bit manipulation in JS? I've never understood when using bit operators could be necessary or even useful. Of course, I'm speaking from my experience building web apps; ruby, python, js, php, etc. I don't have much other programming experience

To do this exercise in javascript is pretty silly. But as a systems developer, I can tell you that bit manipulation happens all over the place in my line of work.

Re: Do you know your bitwise operators?

#15
post #4

This is stated to be a puzzle. But, when does this actually get used? Are there use cases of bit manipulation in JS? I've never understood when using bit operators could be necessary or even useful. Of course, I'm speaking from my experience building web apps; ruby, python, js, php, etc. I don't have much other programming experience

- Packing lots of small pieces of information into a single memory word - for example, 3-3-2 bit RGB [1]

- Interacting with hardware that uses certain bits in a register to control behavior - for example, Arduino digital ports [2]

- Doing arithmetic extra-fast with numbers that are powers of two - modulo becomes bitwise-and, division and multiplication become shifts

[1] http://en.wikipedia.org/wiki/List_of_monochrome_and_RGB_pale...

[2] http://arduino.cc/en/Reference/PortManipulation

Re: Do you know your bitwise operators?

#17
post #4

This is stated to be a puzzle. But, when does this actually get used? Are there use cases of bit manipulation in JS? I've never understood when using bit operators could be necessary or even useful. Of course, I'm speaking from my experience building web apps; ruby, python, js, php, etc. I don't have much other programming experience

This is mostly done in lower level code, so no wonder you have never bumped into it. One easy example, though is passing a set of binary options around, which is useful, for example, when you want to say "enable those features, and disable those other features". You can pack up to 32 options into a 4-byte integer.

Re: Do you know your bitwise operators?

#19
post #4

This is stated to be a puzzle. But, when does this actually get used? Are there use cases of bit manipulation in JS? I've never understood when using bit operators could be necessary or even useful. Of course, I'm speaking from my experience building web apps; ruby, python, js, php, etc. I don't have much other programming experience

real world application: https://github.com/facebook/hhvm/blob/master/hphp/compiler/a...

Re: Do you know your bitwise operators?

#20
post #4

This is stated to be a puzzle. But, when does this actually get used? Are there use cases of bit manipulation in JS? I've never understood when using bit operators could be necessary or even useful. Of course, I'm speaking from my experience building web apps; ruby, python, js, php, etc. I don't have much other programming experience

To do this exercise in javascript is pretty silly. But as a systems developer, I can tell you that bit manipulation happens all over the place in my line of work.

There is nothing inherently javascript about this, besides providing a UI to validate the answer (that's when the validator works...)
Post reply on HN