Prev | Current Page 146 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

In fact, for each place the value is
shifted left, it is multiplied by 2. Shifting right then has the effect of dividing your value by two.
You can combine your shifted integers by simply adding them together, so each value occupies the empty
space of the other values. Once you have shifted your bits and assigned them to the new variable, you
can then retrieve your values by simply shifting the new variable ??™ s value to the right and extracting them.
Filtering Bits
When trying to extract your values, you may notice a small problem. You know that when you shift your
bits and add them together, you are in effect filling empty spaces, but when you then want to extract
your values, you find that the individual values you started with are now corrupting each other. For
example, when combining your four integers, your new variable will have looked like this:
10011011 01010000 00010001 10000011
Here, each group of 8 bits represents one of your original values. If you start shifting right to extract your
values, the left area of each value, with the exception of the far left integer, will be corrupted with each of
the values occupying the higher bits.


Pages:
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158