免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2555 | 回复: 0
打印 上一主题 下一主题

java中实现简单的Int64 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-07-24 21:23 |只看该作者 |倒序浏览
java中貌似没有支持8个字节的类型(这是我的猜测,因为找不到),但是有时候又要用,呵呵~至少我是,只好自己写了一个假的8字节类型Int64,虽然不是很好,但将就可以用一用吧 ^_^

public class Int64
{
    byte[] m_byteData;
    public Int64()
    {
        m_byteData = new byte[8];
    }
    public Int64(String str)
    {
        m_byteData = new byte[8];
        SetValue(str);
    }
    public byte[] Data()
    {
        return m_byteData;
    }
    public void SetValue(String str)
    {
        int len = str.length();
        int count = len / 2;
        String temp = "";
        short num = 0;
        int i = 0;
        for (i = 0; i
            temp = str.substring(i*2+1, i*2+2);
            num = (short)Integer.parseInt(temp);
            m_byteData += (byte)(num);
        }
        if (len % 2 == 1)   // 最后一个数
        {
            temp = str.substring(len-1, len);
            num = (short)Integer.parseInt(temp);
            m_byteData = (byte)(num
            num = 0x0f;   // 加入结束标志
            m_byteData += (byte)(num);            
        }
        else if (i > 4);
            if (temp > 9)
            {
                break;
            }
            str += temp;
            temp = (short) (m_byteData & 0x0f);
            if (temp > 9)
            {
                break;
            }
            str += temp;
        }
        return str;        
    }
    public static String VauleOf(Int64 value)
    {
        String str = "";
        short temp;
        for (int i = 0; i > 4);
            if (temp > 9)
            {
                break;
            }
            str += temp;
            temp = (short) (value.m_byteData & 0x0f);
            if (temp > 9)
            {
                break;
            }
            str += temp;
        }
        return str;
    }
}


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/43056/showart_346018.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP