Ruby Integer size() function with example
Last Updated :
08 Jan, 2020
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:
num1 = 18
num2 = 2 ** 1000
num3 = 2 ** 19
num4 = 5 ** 100
puts num1.size
puts num2.size
puts num3.size
puts num4.size
|
Output:
8
126
8
30
Example #2:
num1 = 18
num2 = 5 ** 1000
num3 = 19 ** 19
num4 = 12 ** 100
puts num1.size
puts num2.size
puts num3.size
puts num4.size
|
Output:
8
291
11
45
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...