Why does this code print 0?
public class A{
public static void main(String str[]){
byte b= (byte) 256;
System.out.println(b);
}}
Printable View
Why does this code print 0?
public class A{
public static void main(String str[]){
byte b= (byte) 256;
System.out.println(b);
}}
Forum Rules -- especially the third paragraph
http://www.java-forums.org/forum-gui...w-members.html
BB Code List - Java Programming Forum
db
You can't stick 256 in a byte; it is too small for that value.
kind regards,
Jos
The hex value of 256 is 0x100.
The 00 is the part that is cast into the byte variable which holds 2 hex digits or 8 bits.