i have following java program:
public class java { public static void main(string[] args) { byte a=64, b; int i; i=a<<2; b=(byte)(a<<2); system.out.println(i); system.out.println(b); } } in program, how value of b zero? didn't it.
because byte 8 bits. , last 8 bits of int 0. if add result of integer.tobinarystring(int) like,
byte = 64; int = << 2; system.out.println(integer.tobinarystring(i)); byte b = (byte) (a << 2); you'll see output is
100000000 so b (because 1 ninth bit) becomes
00000000 (which 0).
Comments
Post a Comment