/**
*<p>项目名称: Java</p>
*<p>文件名称: ByteTest</p>
*<p>版权所有: 版权所有(C)2008-2010</p>
*<p>公 司:
*<p>编写日期: 2008-7-9上午03:36:46</p>
*<p>作 者: huangtao</p>
*/
/**
* @author huangtao
*
*/
public class ByteTest
{
public static void main(String[] args)
{
//声明byte对象
byte a11 = Byte.MAX_VALUE;
byte b11 = Byte.MIN_VALUE;
int c11 = Byte.SIZE;
System.out.println(a11+"_"+b11+"_"+c11);
byte a = 127;
String b = "121";
Byte b1 = new Byte(a);
Byte b2 = new Byte(b);
//获取byte值
System.out.println(b1.byteValue());
System.out.println(b2.byteValue());
System.out.println(b1.compareTo(b2));
System.out.println(b2.compareTo(b1));
Byte b3 = Byte.decode(b);
System.out.println(b3.byteValue());
System.out.println(b1.equals(b2));
System.out.println(b1.longValue());
byte MA = Byte.MAX_VALUE;
byte MI = Byte.MIN_VALUE;
int between = MA-MI;
//获取byte值和对应的hash码
byte[] pb = new byte[MA];//存储正数的空间
byte[] nb = new byte[0-MI];//存储负数的空间
byte[] result = new byte[between];//正数和负数的所在的数组
for(int i = MI , j = 0 ; i<0 ; i++ , j++)
{
nb[j] = (byte) i;
System.out.println("负数1:"+i+"哈希码"+new Byte(nb[j]).hashCode());
}
for(int i = 0 , j = 0 ; i<MA ; i++ , j++)
{
pb[j] = (byte) i;
System.out.println("正数2:"+i+"哈希码"+new Byte(pb[j]).hashCode());
}
//数组复制
System.arraycopy(nb , 0 , result , 0 , nb.length);
System.arraycopy(pb , 0 , result , nb.length , pb.length);
for(int i = 0 ; i<result.length ; i++)
{
System.out.println("所有的数3:"+result[i]+"哈希码"+new Byte((byte) i).hashCode());
}
//获取byte值
String str1 = "1";
String str2 = "24";
String str3 = "1";
System.out.println(Byte.parseByte(str1));
System.out.println(Byte.parseByte(str2));
System.out.println(Byte.parseByte(str3 , 2));
System.out.println(Byte.parseByte(str3 , 8));
System.out.println(Byte.parseByte(str3 , 10));
System.out.println(Byte.parseByte(str3 , 16));
//获取Byte对象
Byte bb1 = Byte.valueOf(Byte.parseByte(str1));
Byte bb2 = Byte.valueOf(Byte.parseByte(str2));
Byte bb3 = Byte.valueOf(Byte.parseByte(str3));
System.out.println(bb1.byteValue());
System.out.println(bb2.byteValue());
System.out.println(bb3.byteValue());
Byte bb41 = Byte.valueOf(str1 , 2);
Byte bb42 = Byte.valueOf(str1 , 8);
Byte bb43 = Byte.valueOf(str1 , 10);
Byte bb44 = Byte.valueOf(str1 , 16);
System.out.println(bb41.byteValue());
System.out.println(bb42.byteValue());
System.out.println(bb43.byteValue());
System.out.println(bb44.byteValue());
}
}