Ruby Integer size() function with example
Last Updated :
08 Jan, 2020
Improve
The size() function in Ruby returns the number of bytes in the machine representation of int.
Syntax: number.size
Parameter: The function takes the integer whose number of bytes is returned.
Return Value: The function returns the number of bytes.
Example #1:
# Ruby program for size() function # Initializing the numbers num1 = 18 num2 = 2 ** 1000 num3 = 2 ** 19 num4 = 5 ** 100 # Printing the size value puts num1.size puts num2.size puts num3.size puts num4.size |
Output:
8 126 8 30
Example #2:
# Ruby program for size() function # Initializing the numbers num1 = 18 num2 = 5 ** 1000 num3 = 19 ** 19 num4 = 12 ** 100 # Printing the number # bytes used puts num1.size puts num2.size puts num3.size puts num4.size |
Output:
8 291 11 45