2 Copyright (c) 2008, Adobe Systems Incorporated
\r
5 Redistribution and use in source and binary forms, with or without
\r
6 modification, are permitted provided that the following conditions are
\r
9 * Redistributions of source code must retain the above copyright notice,
\r
10 this list of conditions and the following disclaimer.
\r
12 * Redistributions in binary form must reproduce the above copyright
\r
13 notice, this list of conditions and the following disclaimer in the
\r
14 documentation and/or other materials provided with the distribution.
\r
16 * Neither the name of Adobe Systems Incorporated nor the names of its
\r
17 contributors may be used to endorse or promote products derived from
\r
18 this software without specific prior written permission.
\r
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
\r
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
\r
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
\r
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
\r
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
\r
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
\r
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
\r
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
\r
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
\r
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
32 package com.adobe.utils {
\r
34 import flash.utils.Endian;
\r
37 * Contains reusable methods for operations pertaining
\r
40 public class IntUtil {
\r
43 * Rotates x left n bits
\r
45 * @langversion ActionScript 3.0
\r
46 * @playerversion Flash 9.0
\r
49 public static function rol ( x:int, n:int ):int {
\r
50 return ( x << n ) | ( x >>> ( 32 - n ) );
\r
54 * Rotates x right n bits
\r
56 * @langversion ActionScript 3.0
\r
57 * @playerversion Flash 9.0
\r
60 public static function ror ( x:int, n:int ):uint {
\r
61 var nn:int = 32 - n;
\r
62 return ( x << nn ) | ( x >>> ( 32 - nn ) );
\r
65 /** String for quick lookup of a hex character based on index */
\r
66 private static var hexChars:String = "0123456789abcdef";
\r
69 * Outputs the hex value of a int, allowing the developer to specify
\r
70 * the endinaness in the process. Hex output is lowercase.
\r
72 * @param n The int value to output as hex
\r
73 * @param bigEndian Flag to output the int as big or little endian
\r
74 * @return A string of length 8 corresponding to the
\r
75 * hex representation of n ( minus the leading "0x" )
\r
76 * @langversion ActionScript 3.0
\r
77 * @playerversion Flash 9.0
\r
80 public static function toHex( n:int, bigEndian:Boolean = false ):String {
\r
84 for ( var i:int = 0; i < 4; i++ ) {
\r
85 s += hexChars.charAt( ( n >> ( ( 3 - i ) * 8 + 4 ) ) & 0xF )
\r
86 + hexChars.charAt( ( n >> ( ( 3 - i ) * 8 ) ) & 0xF );
\r
89 for ( var x:int = 0; x < 4; x++ ) {
\r
90 s += hexChars.charAt( ( n >> ( x * 8 + 4 ) ) & 0xF )
\r
91 + hexChars.charAt( ( n >> ( x * 8 ) ) & 0xF );
\r