I am researching this AS3 code that write a BitString into a ByteArray. Source: JPGEncoder#writeBits()
private var byteout:ByteArray;
private var bytenew:int = 0;
private var bytepos:int = 7;
private function writeBits(bs:BitString):void
{
var value:int = bs.val;
var posval:int = bs.len-1;
while (posval >= 0) {
if (value & uint(1 << posval)) {
bytenew |= uint(1 << bytepos);
}
posval--;
bytepos--;
if (bytepos < 0) {
if (bytenew == 0xFF) {
writeByte(0xFF);
writeByte(0);
} else {
writeByte(bytenew);
}
bytepos=7;
bytenew=0;
}
}
}
But I don't understand part of the code.
- What is
uint(1 << bytepos)? - What is the if condition
if (value & uint(1 << posval))?- I don't know whether the
&is "and" bit operator, or "and" condition. - Does
if(number)in AS3 meansif(number != 0)?
- I don't know whether the
What is these AS3 code equivalent in Java?