Byte in Java

  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 = 0×7F; 
  If (c == b) System.out.println ( "b == c"); 
  If (127 == 0×7F) System.out.println ( "127 == 0×7F"); 

  B = -128; 
  / / C = 0×80; / / Cannot convert from int to byte 
  C = (byte) 0×80; 
  If (c == b) System.out.println ( "b == c"); 
  If (-128 == 0×80) System.out.println ( "-128 == 0×80"); 
  If (128 == 0×80) System.out.println ( "128 == 0×80"); 

  C = (byte) 0×80; 
  If (c == 128) System.out.println ( "128 == c"); 
  If (c == -128) System.out.println ( "-128 == c"); 
  If (== 128 (c & 0xFF)) System.out.println ( "== 128 (c & 0xFF)"); 
  ) 
  ) 
  Output: 
  B = c 
  127 == 0×7F 
  B = c 
  128 == 0×80 
  == C -128 
  == 128 (c & 0xFF) 

  Posted on 2007-07-17 23:22 Job Hu Reading (24) Comments (0) edit collections cited 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags: , , , , , , , , ,

Releated Java Articles

Comments

Leave a Reply