If you're truly interested in bitwise stuff google/youtube has a bunch of stuff. Most people don't explain it very well though.
One video that did an okay job is
https://www.youtube.com/watch?v=Nm4u3kCEKo8To be honest you need to find one that shows the before operations in binary and after result in binary, so you can physically see the results and the bits moving around. I haven't found such video yet as most people skim right past everything without explaining the core concept.
edit:: At the end of that video it quickly dives into bitwise flags. These could be useful for a lot of things. On/off options, positional checks, etc.
For example say you have a array with 8 elements. You could use a 1 byte (8 bit) number to represent if that specific element is used or not.
Pseudo code, don't shoot me.Code
array = Array(8).new
bitmast = Byte.new;
array[3] = "this is used"
bitmask ^= 0b0000_1000 #=> bitmast is now 0000_1000
array[7] = "this is now used"
bitmask ^= 0b1000_0000 bitmast is now 1000_1000
Then rather than iterating the entire array to find if a position is filled you can either poll each bit position checking for 1, or return all full bits and iterate the bit mask looking for the first free space:
Code
#is position 1 full?
if(bitmask & 0b0000_0010) {
#no its not
} else {
#yes it is
}
bitcopy = Byte.new;
bitcopy = bitmask #make a copy of the bitmask
for(int i = 0; i <= 8; i++) { #iterate each position of the bitmask
if(botcopy & 0b0000_0001) { #if our current index is full
bitcopy = bitcopy >> 1; #shift our bitmask over 1 bit so we can check the next element
next;
} else {
#i holds the index that is free; #the bitmask held a 0 so that element is empty.
}
}
Sure this isn't that useful in a structured language but it is another use once you start doing networking or other technical programming.
Unfortunately you can't easily visualize how the bits are moving unless seeing a live demo.
This post was edited by AbDuCt on Jun 21 2016 07:09pm