I want to pack epoch milliseconds into 6 bytes but i have problem. Let me introduce it:
trace(t);
for (var i:int = 6; i > 0; i--) {
dataBuffer.writeByte(((t >>> 8*(i-1)) & 255));
trace(dataBuffer[dataBuffer.length - 1]);
}
Output:
1330454496254
131
254
197
68
131
254
What i’m doing wrong?
I’m just guessing but I think your
tvariable is getting automatically converted to anintbefore the bit operation takes effect. This, of course, destroys the value.I don’t think it’s possible to use
Numberin bit operations – AS3 only supports those withint-s.Depending on how you acquire the value in
t, you may want to start with 2int-s and then extrat the bytes from those.