Skip to content

Instantly share code, notes, and snippets.

@lynxerzhang
Last active October 3, 2015 05:18
Show Gist options
  • Save lynxerzhang/2399158 to your computer and use it in GitHub Desktop.
Save lynxerzhang/2399158 to your computer and use it in GitHub Desktop.
Rotate bits function
//TODO
function rotateBits(values:uint, extent:int):uint{
var offset:uint;
const bytesAll:int = 32;
if(extent == 0){
return values;
}
extent = extent % bytesAll;
if(extent > 0){
offset = values >>> (32 - extent);
values = offset | (values << extent);
}
else{
extent = -extent;
offset = values << (32 - extent);
values = offset | (values >> extent);
}
return values;
}
trace(this.rotate(1, -1));
trace(this.rotate(2147483648, 2));
trace(this.rotate(2, 2));
trace(this.rotate(8, 1));
//http://www.tongwenguan.com/?p=1885
//I read this tutorial, and try it in ActionScript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment