Page 34 - CTS - CSA TP - Volume 2
P. 34
COMPUTER SOFTWARE APPLICATION - CITS
• System.out.println(10 << 3);
• Left shift the binary representation of 10 by 3 positions.
• After left shifting by 3, 10 becomes 1010000, which is 80 in decimal.
• Output: 80
• System.out.println(20 << 2);
• Left shift the binary representation of 20 by 2 positions.
• After left shifting by 2, 20 becomes 101000, which is 80 in decimal.
• Output: 80
• System.out.println(15 << 4);
• Left shift the binary representation of 15 by 4 positions.
• After left shifting by 4, 15 become 11110000, which is 240 in decimal.
• Output: 240
Output:
TASK 7: Java Right Shift Operator Example
public class OperatorExample7{
public static void main(String args[]){
System.out.println(10>>2);//10/2^2=10/4=2
System.out.println(20>>2);//20/2^2=20/4=5
System.out.println(20>>3);//20/2^3=20/8=2
}}
Explanation:
1 Right Shift Operator (>>):
• The right shift operator (>>) shifts the bits of a binary number to the right by a specified number of positions.
• The general form is value >> numBits, where value is the number to be shifted, and numBits is the number
of positions to shift.
2 Bitwise Right Shift Operations:
• The program performs right shift operations on various integers.
19
CITS : IT & ITES - Computer Software Application - Exercise 82 CITS : IT & ITES - Computer Software Application - Exercise 82