* Readonly document view.
[redakcja.git] / platforma / static / filebrowser / uploadify / com / adobe / utils / IntUtil.as
1 /*\r
2   Copyright (c) 2008, Adobe Systems Incorporated\r
3   All rights reserved.\r
4 \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
7   met:\r
8 \r
9   * Redistributions of source code must retain the above copyright notice, \r
10     this list of conditions and the following disclaimer.\r
11   \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
15   \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
19 \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
31 */\r
32 package com.adobe.utils {\r
33         \r
34         import flash.utils.Endian;\r
35         \r
36         /**\r
37          * Contains reusable methods for operations pertaining \r
38          * to int values.\r
39          */\r
40         public class IntUtil {\r
41                 \r
42                 /**\r
43                  * Rotates x left n bits\r
44                  *\r
45                  * @langversion ActionScript 3.0\r
46                  * @playerversion Flash 9.0\r
47                  * @tiptext\r
48                  */\r
49                 public static function rol ( x:int, n:int ):int {\r
50                         return ( x << n ) | ( x >>> ( 32 - n ) );\r
51                 }\r
52                 \r
53                 /**\r
54                  * Rotates x right n bits\r
55                  *\r
56                  * @langversion ActionScript 3.0\r
57                  * @playerversion Flash 9.0\r
58                  * @tiptext\r
59                  */\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
63                 }\r
64                 \r
65                 /** String for quick lookup of a hex character based on index */\r
66                 private static var hexChars:String = "0123456789abcdef";\r
67                 \r
68                 /**\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
71                  *\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
78                  * @tiptext\r
79                  */\r
80                 public static function toHex( n:int, bigEndian:Boolean = false ):String {\r
81                         var s:String = "";\r
82                         \r
83                         if ( bigEndian ) {\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
87                                 }\r
88                         } else {\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
92                                 }\r
93                         }\r
94                         \r
95                         return s;\r
96                 }\r
97         }\r
98                 \r
99 }