This is a Java program that demonstrates the left shift operator.
Note that the left shift operator can be used to perform multiplication by a power of 2, which is faster than using the multiplication operator (*) when working with large numbers. However, it should be used with caution as it can also lead to unexpected results when used with negative numbers.
public class LeftShift_Operator { public static void main(String[] args) { int num = 0xff; System.out.printf("Number before left shift: %04X\n", num); num = (num << 3); //shifting 3 bits left System.out.printf("Number after left shift: %04X\n", num); } }
Number before left shift: 00FF Number after left shift: 07F8
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions