Skip to content
Related Articles

Related Articles

Ruby | Integer >> method
  • Last Updated : 18 Dec, 2019

The >> is an inbuilt method in Ruby returns the number which is shifted N times to the right. The resultant number is int(num / (2^N)).

Syntax: num >> N

Parameters: The function accepts no parameter.

Return Value: It returns int(num / (2^N)).

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for >> method in Integer 
    
# Initialize numbers 
num1 = 6
num2 = 1
  
# Prints 6 shifted 1 time 
print num1 >> num2

chevron_right


Output:

3

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for >> method in Integer 
    
# Initialize numbers 
num1 = 2
num2 = 2 
  
# Prints 2 shifted 2 times 
print num1 >> num2

chevron_right


Output:

0
My Personal Notes arrow_drop_up
Recommended Articles
Page :