Binary in JavaScript
danthedev.com
danthedev.com
- The whole object and string representation thing is naïve to the point of total incorrectness. Where is the object and its length and type stored, for example? And browsers intern strings (store them once with garbage collection of some form to clear out the values when they are no longer needed) and don’t use null-terminated things (otherwise you couldn’t have "\0"), so your 320 bits is actually more likely to be 192 or 96, with the full 320 bits plus approximately three or six more words occurring only once. (I’m being a little vague about this because I’m not familiar with what specific techniques are actually used in browsers at present.) The end result of it all is that the actual figure will, I think, be more like 30–50 bytes per tile, not 60. (Then again, it may end up more, and it will definitely depend on the browser; I’m not up to date with the performance- and memory-efficiency techniques used.) I’m complaining here only because it’s misleading about how things are done; the concerns it raises are absolutely genuine.
- Bitwise operations on numbers are only 32-bit, not 64-bit. You want 64-bit bitwise operations? There’s no native support for it, you’ll need to emulate it. This is a part of the tangled mess that is a unified number type which can be either a 32-bit integer or a 64-bit floating point number.
https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/...
This is the first time I see someone giving a good real world example of bitwise operators that I can understand.
http://stackoverflow.com/questions/11400242/bit-vector-imple...
This would save a lot of initial loading time and could support maps much larger than 512 x 512.
var vegetation = require('ndarray-bit')([512, 512])
vegetation.set(23, 42, true)
vegetation.get(23, 42) // trueNever thought that there were people doing Javascript who didn't know about bitwise operators. I guess I know where 99% of the "Javascript sucks" posts come from.
It is also badly designed and disliked as far as I can tell just about universally in every aspect as a language. Objective C is also blazingly fast and powerful if you use it correctly but not everyone wants to. It isn't about not knowing it has access to bitwise operators.
These can be queried using bitwise operations and you can abstract all of it with synthetic instance properties.
User.email_enabled = true would translate to 0010 or something in, for example, a properties column.
Really handy stuff!!!
I think that unless you're having space issues, you're better off using boolean columns.
Bitmasking is a useful technique in some places, but storing user preferences isn't one of them. It's 'cleverness' for the sake of being clever - the code is harder to read, new developers can't immediately understand it, experienced developers have to look up what flags mean, you can't just dump the database row to see what a user's preference are, and if your documentation ever gets out of sync you're screwed.
For the sake of saving DB space it's a really bad idea.