4 ms·
I wonder why the author chooses to write buf[offset]*256 + buf[offset+1] instead of the more common method to load bytes using bitwise arithmetic, e.g. b[k]<<8
by paavoova 8y ago
I wonder why the author chooses to write buf[offset]*256 + buf[offset+1] instead of the more common method to load bytes using bitwise arithmetic, e.g. b[k]<<8 | b[k+1]. This is far clearer instead of using potentially magic numbers. Does Javascript not have bitwise arithmetic? Why would you write C code with Javascript in mind?
- michaelg7x 8y agoIf b is uint8_t you get zero if you <<8, but the expected value if you * by (int)256; or is it late and I should keep quiet?
- 0xffff2 8y agoThe shift will automatically promote `b` to int, so the result is identical in both cases.
- michaelg7x 8y agoThanks. I'm mostly paranoid about whether the ROL instruction has precedence over the OR ... ;)