actionscript 3.0 cookbook:Int64与Number转换
来源:互联网 发布:快递如何找淘宝客户 编辑:程序博客网 时间:2024/05/16 02:01
package com.netease.protobuf {
public final class Int64 extends Binary64 {
public final function set high(value:int):void {
internalHigh = value
}
public final function get high():int {
return internalHigh
}
public function Int64(low:uint = 0, high:int = 0) {
super(low, high)
}
/**
* Convert from <code>Number</code>.
*/
public static function fromNumber(n: Number):Int64 {
return new Int64(n, Math.floor(n / 4294967296.0))
}
/**
* Convert to <code>Number</code>.
*/
public final function toNumber():Number {
return high * 4294967296.0 + low
}
public final function toString(radix:uint = 10):String {
if (radix < 2 || radix > 36) {
throw new ArgumentError
}
switch (high) {
case 0:
{
return low.toString(radix)
}
case -1:
{
if ((low & 0x80000000) == 0)
{
return (int(low | 0x80000000) - 2147483648.0).toString(radix)
}
else
{
return int(low).toString(radix)
}
}
default:
{
break;
}
}
if (low == 0 && high == 0) {
return "0"
}
const digitChars:Array = [];
const copyOfThis:UInt64 = new UInt64(low, high);
if (high < 0) {
copyOfThis.bitwiseNot()
copyOfThis.add(1)
}
do {
const digit:uint = copyOfThis.div(radix);
if (digit < 10) {
digitChars.push(digit + CHAR_CODE_0);
} else {
digitChars.push(digit - 10 + CHAR_CODE_A);
}
} while (copyOfThis.high != 0)
if (high < 0) {
return '-' + copyOfThis.low.toString(radix) +
String.fromCharCode.apply(
String, digitChars.reverse())
} else {
return copyOfThis.low.toString(radix) +
String.fromCharCode.apply(
String, digitChars.reverse())
}
}
public static function parseInt64(str:String, radix:uint = 0):Int64 {
const negative:Boolean = str.search(/^\-/) == 0
var i:uint = negative ? 1 : 0
if (radix == 0) {
if (str.search(/^\-?0x/) == 0) {
radix = 16
i += 2
} else {
radix = 10
}
}
if (radix < 2 || radix > 36) {
throw new ArgumentError
}
str = str.toLowerCase()
const result:Int64 = new Int64
for (; i < str.length; i++) {
var digit:uint = str.charCodeAt(i)
if (digit >= CHAR_CODE_0 && digit <= CHAR_CODE_9) {
digit -= CHAR_CODE_0
} else if (digit >= CHAR_CODE_A && digit <= CHAR_CODE_Z) {
digit -= CHAR_CODE_A
digit += 10
} else {
throw new ArgumentError
}
if (digit >= radix) {
throw new ArgumentError
}
result.mul(radix)
result.add(digit)
}
if (negative) {
result.bitwiseNot()
result.add(1)
}
return result
}
}
public final class Int64 extends Binary64 {
public final function set high(value:int):void {
internalHigh = value
}
public final function get high():int {
return internalHigh
}
public function Int64(low:uint = 0, high:int = 0) {
super(low, high)
}
/**
* Convert from <code>Number</code>.
*/
public static function fromNumber(n: Number):Int64 {
return new Int64(n, Math.floor(n / 4294967296.0))
}
/**
* Convert to <code>Number</code>.
*/
public final function toNumber():Number {
return high * 4294967296.0 + low
}
public final function toString(radix:uint = 10):String {
if (radix < 2 || radix > 36) {
throw new ArgumentError
}
switch (high) {
case 0:
{
return low.toString(radix)
}
case -1:
{
if ((low & 0x80000000) == 0)
{
return (int(low | 0x80000000) - 2147483648.0).toString(radix)
}
else
{
return int(low).toString(radix)
}
}
default:
{
break;
}
}
if (low == 0 && high == 0) {
return "0"
}
const digitChars:Array = [];
const copyOfThis:UInt64 = new UInt64(low, high);
if (high < 0) {
copyOfThis.bitwiseNot()
copyOfThis.add(1)
}
do {
const digit:uint = copyOfThis.div(radix);
if (digit < 10) {
digitChars.push(digit + CHAR_CODE_0);
} else {
digitChars.push(digit - 10 + CHAR_CODE_A);
}
} while (copyOfThis.high != 0)
if (high < 0) {
return '-' + copyOfThis.low.toString(radix) +
String.fromCharCode.apply(
String, digitChars.reverse())
} else {
return copyOfThis.low.toString(radix) +
String.fromCharCode.apply(
String, digitChars.reverse())
}
}
public static function parseInt64(str:String, radix:uint = 0):Int64 {
const negative:Boolean = str.search(/^\-/) == 0
var i:uint = negative ? 1 : 0
if (radix == 0) {
if (str.search(/^\-?0x/) == 0) {
radix = 16
i += 2
} else {
radix = 10
}
}
if (radix < 2 || radix > 36) {
throw new ArgumentError
}
str = str.toLowerCase()
const result:Int64 = new Int64
for (; i < str.length; i++) {
var digit:uint = str.charCodeAt(i)
if (digit >= CHAR_CODE_0 && digit <= CHAR_CODE_9) {
digit -= CHAR_CODE_0
} else if (digit >= CHAR_CODE_A && digit <= CHAR_CODE_Z) {
digit -= CHAR_CODE_A
digit += 10
} else {
throw new ArgumentError
}
if (digit >= radix) {
throw new ArgumentError
}
result.mul(radix)
result.add(digit)
}
if (negative) {
result.bitwiseNot()
result.add(1)
}
return result
}
}
}
更多关于actionscript 3.0 cookbook的知识可以查询天地会http://bbs.9ria.com/thread-25133-1-1.html
0 0
- actionscript 3.0 cookbook:Int64与Number转换
- ActionScript 3.0 Cookbook勘误
- ActionScript 3.0 Cookbook [ILLUSTRATED]
- 《ActionScript.3.0.Cookbook》
- ActionScript.3.0.Cookbook.中文完整版.pdf
- Actionscript与Java数据类型转换
- ActionScript 3.0 Cookbook 6.3向前或向后移动对象翻译
- 转换字符串成INT64
- ActionScript 3 Cookbook 简体中文版 目录
- int64
- ActionScript 3.0 Cookbook 6.1添加一个项目到可视化列表中
- ActionScript 3.0 Cookbook 6.2 从显示列表中移除项目(翻译:转载请注明)
- ActionScript 3 Cookbook 中文版 第一章. ActionScript 语言基础
- ActionScript 3 Cookbook 中文版 第一章. ActionScript 语言基础
- ActionScript 3 Cookbook 繁体中文版 下载地址
- 精通Flex 3.0――14.1.2 ActionScript与Java数据类型的转换
- ActionScript 3.0 学习(三) AS3数据类型转换
- Python Cookbook 1.2 字符与数字的相互转换
- 【IT实施培训那些事儿】
- 查询SQLServer的启动时间
- Hello CSDN
- 解析对应的XML文件(英雄会)
- Lucene分词的注意事项
- actionscript 3.0 cookbook:Int64与Number转换
- 让我的头像圆起来--Android之圆头像
- 模拟Windows登录用户进行特殊操作
- XUBUNTU-8.04-a6版本中安装BCM43XX无线网卡的BUG修正方法
- 数据包捕获
- apk打包过程图解
- 第五届蓝桥杯——入门训练 序列求和
- 不规则div的写法
- ubuntu 12.04LTS 用终端安装vmware tools