This is a Java program that demonstrates the right shift operator.
Note that the right shift operator can be used to perform division by a power of 2, which is faster than using the division 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.
import java.util.Scanner; public class RightShift_Operator { public static void main(String[] args) { int num = 0xff; System.out.printf("Number before right shift: %04X\n", num); num = (num >> 3);//shifting 3 bits right System.out.printf("Number after right shift: %04X\n", num); } }
Number before right shift: 00FF Number after right shift: 001F
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions