actionscript 3 - what is the fastest way to 'zip' a binary stream? -
suggest there binary stream contains 8 bytes
i want new stream contains this:
take every first bit of each bite form first byte
take every second bit of each bite form second byte
....
take every 8th bit of each bite form last byte
just zip() in python in binary form.
here's code
//create example data var ba:bytearray = new bytearray(); for(var i:int=0;i<8;i++){ ba.writebyte(math.random()*256); } ba.position = 0; //process 8 bytes var eightbytes:array = new array(); for(i=0;i<8;i++){ eightbytes.push(ba.readbyte()); } var j:int = 128; var ba2:bytearray = new bytearray(); for(i=0;i<8;i++){ var result:int = 0; for(var k:int = 0;k<8;k++){ var byte:int = eightbytes[k]&j; if(i<k){ byte = byte>>(k-i); }else if(i>k){ byte = byte<<(i-k); } result=result||byte; } ba2.writebyte(result); j=j>>1; } trace(ba); trace(ba2);
this not @ dealing large amount of data.i have read , write bytes 1 one, , 8x8 loops every 8-bytes block.is there way can fasten it?
check out workers, closest thing threads in as3. parallel calculations , after wait 8 finish combine result. stop interface locking because of calculations.
Comments
Post a Comment