Ruby Integer size()函数与示例
Ruby 中的size()函数以 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.
示例 #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
输出:
8
126
8
30
示例 #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
输出:
8
291
11
45