Something I find handy while programming is being able to use the bits in an integer-type variable as boolean flags. What I mean by that is, let’s say you have an INT that is 4 bytes in size. Each byte consists of 8 bits so this INT contains 32 bits in total (4 bytes * 8 bits in a byte). If we have a program that has 32 different boolean variables, wouldn’t it be more effective to store all of them in a single integer variable? This would especially be helpful when you want to keep your networking packets small. 32 booleans in 4 bytes instead of 32 bytes! Ultimately, it’s up to you to decide how to use it; I’m just here to show you how.
Read the rest of this entry »