Bits can be an intimitating programming concept but once you grasp the fundamentals, it is a very simple concept. There are a few key things to remember, bit vector, bit shifting, and bit manipulation.
A bit vector is not a difficult concept. In fact, if you are familiar with low level computer concepts and architectures, it should be easy for you to understand. A bit vector is simply an array of bits. It is that simple. Except this array of bits is normally represented as an unsigned integer to reduce memory consumption.
We will use the case of an 8-bit machine, thus the unsigned integer is 1 byte, which is 8 bits. Thus, a bit vector represented by an int is an array of 8 bits. Each bit is represented by a particular combination of values of the integer.
For example, the integer 1 is the bit vector 00000001.
The integer 2 is the bit vector 000000010.
The integer 3 is the bit vector 000000011.
If you noticed, the bit vector is simply the binary representation of the unsigned integer.
Bit shifting is another very simple concept. The idea is to shift the array of bits. For example, in Java, to bit shift left by 1 slot, we do this "00000001 << 1". This produces 00000010.
A key way to check is that each shift to the left doubles the value, while each shift to the right halves the value.
Simply take the number on the right side, and shift the ways in the array that many times in the direction of the arrows.
There are many methods to manipulate a bit array. It is often used for conditional checks, called bit masking.
Suppose we have the two bit arrays, 00101100 and 10101010. Applying the mask & (and), we get 00101000. We return a 1 in the case where both bits are 1 in that slot, otherwise we return a 0. It is just the simple "and" defintion.
The other bit masks includes XOR (^), and OR (|). XOR, exclusive or, returns a 1 if either bit is 1, but not both. The OR is just the normal defintion, return a 1 if either of the bits is 1.
I truly appreciate this post. I have been looking everywhere for this! Thank goodness I found it on Bing. You have made my day! Thanks again!
<a href="http://www.bagmulberry.co.uk" title="mulberry">mulberry</a>
You have remarked very interesting points ! ps nice internet site . "I'm going to a special place when I die, but I want to make sure my life is special while I'm here." by Payne Stewart.
[url=http://www.superclassicboots.com/ugg-5825-short-boots-c-21.html]ugg classic short[/url]
<a href="http://www.superclassicboots.com/ugg-5825-short-boots-c-21.html" title="ugg classic short">ugg classic short</a>
Very interesting information!Perfect just what I was searching for!
[url=http://bestwaytolosestomachfatformen.blogspot.com]How To Lose Stomach Fat[/url]
<a href="http://bestwaytolosestomachfatformen.blogspot.com" title="How To Lose Stomach Fat">How To Lose Stomach Fat</a>
Merely wanna input on few general things, The website design is perfect, the subject material is really superb. "The stars are constantly shining, but often we do not see them until the dark hours." by Earl Riney.
<a href="http://pinterest.com/daniel0128/mulberry-bags/" title="mulberry handbags">mulberry handbags</a>
Just wanna tell that this is very beneficial , Thanks for taking your time to write this.
<a href="http://www.cameraamazon.info/" title="digital camera">digital camera</a>