Re: bitwise operators
I used bitwise in C++ once for a maze generation system. Instead of having lots of boolean values (thereby wasting precious memory) I used a single 32-bit integer (or was it 64) to represent all the flags for each cell. For example, I used something like if ((cell.flags&Door)==1) to test if it was a door and so on. That same integer also held directional flags as well, so it was used for quite a lot of things. To add a flag, I used the &= operator, which is identical to doing cell.flags = cell.flags & flag. For removing bits/flag negation, I used the &= operator combined with the ~ operator, making it cell.flags&=~flag. A good way of describing bit shifts is to imagine your bits as an infinite stream of ones and zeros. This infinite stream is your programs address space, since bitwise operations can happen anywhere in the address space (and if your writing an OS driver or kernel, it can happen *anywhere*). If you bit shift to the left (x<<y), you are shifting the x-bit to the left by y positions; i.e.: the y-bit becomes the x-bit. Similarly, if you bit shift to the right (x>>y), the x-bit becomes the y-bit, the exact opposite of the bit shift to the left. (Please correct me if I am wrong; I'm attempting to paraphrase this topic when I was reading low-level assembly language documentation on developing OS kernels -- I tried and failed at that, BTW. Always triple-faulted, and I could never find out why, since my kernel (which I only wanted to print "hello world") didn't support serial ports. Perhaps I should try that again sometime.)
-- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector