随笔 - 8, 文章 - 0, 评论 - 6, 引用 - 0
数据加载中……

Byte in Java


public class ByteTest
{
    
public static void main(String[] args)
    
{
        
byte b;
        
byte c;
        
//b = 255; //Cannot convert from int to byte
        
//b = 0xFF; //Cannot convert from int to byte
        b = 127;
        c 
= 0x7F;
        
if(b == c) System.out.println("b == c");
        
if(127 == 0x7F) System.out.println("127 == 0x7F");
        
        b 
= -128;
        
//c = 0x80; //Cannot convert from int to byte
        c = (byte)0x80;
        
if(b == c) System.out.println("b == c");
        
if(-128 == 0x80) System.out.println("-128 == 0x80");
        
if(128 == 0x80) System.out.println("128 == 0x80"); 
        
        c 
= (byte)0x80;
        
if(128 == c) System.out.println("128 == c");
        
if(-128 == c) System.out.println("-128 == c");
        
if(128 == (c&0xFF)) System.out.println("128 == (c&0xFF)");
    }

}

输出:
b == c
127 == 0x7F
b == c
128 == 0x80
-128 == c
128 == (c&0xFF)

posted on 2007-07-17 23:22 Job Hu 阅读(282) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: