--- /dev/null
+/*\r
+ Copyright (c) 2008, Adobe Systems Incorporated\r
+ All rights reserved.\r
+\r
+ Redistribution and use in source and binary forms, with or without \r
+ modification, are permitted provided that the following conditions are\r
+ met:\r
+\r
+ * Redistributions of source code must retain the above copyright notice, \r
+ this list of conditions and the following disclaimer.\r
+ \r
+ * Redistributions in binary form must reproduce the above copyright\r
+ notice, this list of conditions and the following disclaimer in the \r
+ documentation and/or other materials provided with the distribution.\r
+ \r
+ * Neither the name of Adobe Systems Incorporated nor the names of its \r
+ contributors may be used to endorse or promote products derived from \r
+ this software without specific prior written permission.\r
+\r
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS\r
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR \r
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\r
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+*/\r
+package com.adobe.utils {\r
+ \r
+ import flash.utils.Endian;\r
+ \r
+ /**\r
+ * Contains reusable methods for operations pertaining \r
+ * to int values.\r
+ */\r
+ public class IntUtil {\r
+ \r
+ /**\r
+ * Rotates x left n bits\r
+ *\r
+ * @langversion ActionScript 3.0\r
+ * @playerversion Flash 9.0\r
+ * @tiptext\r
+ */\r
+ public static function rol ( x:int, n:int ):int {\r
+ return ( x << n ) | ( x >>> ( 32 - n ) );\r
+ }\r
+ \r
+ /**\r
+ * Rotates x right n bits\r
+ *\r
+ * @langversion ActionScript 3.0\r
+ * @playerversion Flash 9.0\r
+ * @tiptext\r
+ */\r
+ public static function ror ( x:int, n:int ):uint {\r
+ var nn:int = 32 - n;\r
+ return ( x << nn ) | ( x >>> ( 32 - nn ) );\r
+ }\r
+ \r
+ /** String for quick lookup of a hex character based on index */\r
+ private static var hexChars:String = "0123456789abcdef";\r
+ \r
+ /**\r
+ * Outputs the hex value of a int, allowing the developer to specify\r
+ * the endinaness in the process. Hex output is lowercase.\r
+ *\r
+ * @param n The int value to output as hex\r
+ * @param bigEndian Flag to output the int as big or little endian\r
+ * @return A string of length 8 corresponding to the \r
+ * hex representation of n ( minus the leading "0x" )\r
+ * @langversion ActionScript 3.0\r
+ * @playerversion Flash 9.0\r
+ * @tiptext\r
+ */\r
+ public static function toHex( n:int, bigEndian:Boolean = false ):String {\r
+ var s:String = "";\r
+ \r
+ if ( bigEndian ) {\r
+ for ( var i:int = 0; i < 4; i++ ) {\r
+ s += hexChars.charAt( ( n >> ( ( 3 - i ) * 8 + 4 ) ) & 0xF ) \r
+ + hexChars.charAt( ( n >> ( ( 3 - i ) * 8 ) ) & 0xF );\r
+ }\r
+ } else {\r
+ for ( var x:int = 0; x < 4; x++ ) {\r
+ s += hexChars.charAt( ( n >> ( x * 8 + 4 ) ) & 0xF )\r
+ + hexChars.charAt( ( n >> ( x * 8 ) ) & 0xF );\r
+ }\r
+ }\r
+ \r
+ return s;\r
+ }\r
+ }\r
+ \r
+}
\ No newline at end of file