Prev | Current Page 148 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

This will force all bits after the
first 8 to be discarded:
AND OR XOR
01001011
11011010
01001010 11011011 10010001
10111001
00011011
00011001 10111011 10100010
10110111
01100010
00100010 11110111 11010101
Chapter 3: Learning the Basics
63
10011011 01010000 00010001 10000011 &
00000000 00000000 00000000 11111111 =
-----------------------------------
00000000 00000000 00000000 10000011
You then simply shift the original value to the right by 8 bits and repeat for the next value. Applying this
to your original problem, your class might look like this:
class ShiftBits
{
public static function main()
{
var newInt:Int;
newInt = 155 + (80 < < 8) + (17 < < 16) + (131 < < 24);
trace(newInt & 255);
trace(newInt > > 8 & 255);
trace(newInt > > 16 & 255);
trace(newInt > > 24 & 255);
}
}
Try compiling this program and see for yourself.
The Math Class
Don ??™ t panic; it is not a discussion about school here. However, you have been looking at number values,
so sooner or later, you must start doing some math with your values.


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