如何在 ruby 中声明 8 位无符号整数?
In c++ you can do:
uint8 foo_bar
How would we do the same thing in ruby? Any alternatives?
This post seems close to it maybe someone can explain?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Ruby 抽象了整数的内部存储,因此您不必担心它。
如果将整数分配给变量,Ruby 将处理内部事务,在需要时分配内存。较小的整数的类型为
Fixnum
(存储在一个单词中),较大的整数属于Bignum
类型。Ruby 是动态类型的,因此您不能强制变量仅包含无符号 8 位整数(就像不能强制变量仅包含字符串值等一样)。
Ruby abstracts away the internal storage of integers, so you don't have to worry about it.
If you assign an integer to a variable, Ruby will deal with the internals, allocating memory when needed. Smaller integers are of type
Fixnum
(stored in a single word), larger integers are of typeBignum
.Ruby is dynamically typed, so you cannot force a variable to contain only unsigned 8-bit integers (just as you cannot force a variable to only contain string values, etc.).
您无需在 Ruby 中声明类型。该语言是动态类型的。
You don't declare types in Ruby. The language is dynamically typed.