Mercurial > hg > audiodb
comparison bindings/as3/ext/com/adobe/utils/IntUtil.as @ 732:3a0b9700b3d2
* Initial AS3 commit
author | mas01mj |
---|---|
date | Tue, 14 Sep 2010 16:47:10 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
731:65134dd772fc | 732:3a0b9700b3d2 |
---|---|
1 /* | |
2 Copyright (c) 2008, Adobe Systems Incorporated | |
3 All rights reserved. | |
4 | |
5 Redistribution and use in source and binary forms, with or without | |
6 modification, are permitted provided that the following conditions are | |
7 met: | |
8 | |
9 * Redistributions of source code must retain the above copyright notice, | |
10 this list of conditions and the following disclaimer. | |
11 | |
12 * Redistributions in binary form must reproduce the above copyright | |
13 notice, this list of conditions and the following disclaimer in the | |
14 documentation and/or other materials provided with the distribution. | |
15 | |
16 * Neither the name of Adobe Systems Incorporated nor the names of its | |
17 contributors may be used to endorse or promote products derived from | |
18 this software without specific prior written permission. | |
19 | |
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | |
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | |
22 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
23 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
31 */ | |
32 package com.adobe.utils { | |
33 | |
34 import flash.utils.Endian; | |
35 | |
36 /** | |
37 * Contains reusable methods for operations pertaining | |
38 * to int values. | |
39 */ | |
40 public class IntUtil { | |
41 | |
42 /** | |
43 * Rotates x left n bits | |
44 * | |
45 * @langversion ActionScript 3.0 | |
46 * @playerversion Flash 9.0 | |
47 * @tiptext | |
48 */ | |
49 public static function rol ( x:int, n:int ):int { | |
50 return ( x << n ) | ( x >>> ( 32 - n ) ); | |
51 } | |
52 | |
53 /** | |
54 * Rotates x right n bits | |
55 * | |
56 * @langversion ActionScript 3.0 | |
57 * @playerversion Flash 9.0 | |
58 * @tiptext | |
59 */ | |
60 public static function ror ( x:int, n:int ):uint { | |
61 var nn:int = 32 - n; | |
62 return ( x << nn ) | ( x >>> ( 32 - nn ) ); | |
63 } | |
64 | |
65 /** String for quick lookup of a hex character based on index */ | |
66 private static var hexChars:String = "0123456789abcdef"; | |
67 | |
68 /** | |
69 * Outputs the hex value of a int, allowing the developer to specify | |
70 * the endinaness in the process. Hex output is lowercase. | |
71 * | |
72 * @param n The int value to output as hex | |
73 * @param bigEndian Flag to output the int as big or little endian | |
74 * @return A string of length 8 corresponding to the | |
75 * hex representation of n ( minus the leading "0x" ) | |
76 * @langversion ActionScript 3.0 | |
77 * @playerversion Flash 9.0 | |
78 * @tiptext | |
79 */ | |
80 public static function toHex( n:int, bigEndian:Boolean = false ):String { | |
81 var s:String = ""; | |
82 | |
83 if ( bigEndian ) { | |
84 for ( var i:int = 0; i < 4; i++ ) { | |
85 s += hexChars.charAt( ( n >> ( ( 3 - i ) * 8 + 4 ) ) & 0xF ) | |
86 + hexChars.charAt( ( n >> ( ( 3 - i ) * 8 ) ) & 0xF ); | |
87 } | |
88 } else { | |
89 for ( var x:int = 0; x < 4; x++ ) { | |
90 s += hexChars.charAt( ( n >> ( x * 8 + 4 ) ) & 0xF ) | |
91 + hexChars.charAt( ( n >> ( x * 8 ) ) & 0xF ); | |
92 } | |
93 } | |
94 | |
95 return s; | |
96 } | |
97 } | |
98 | |
99 } |