如何在ruby中声明8位无符号整数? [英] How to declare 8-bit unsigned integer in ruby?

查看:102
本文介绍了如何在ruby中声明8位无符号整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在c ++中你可以这样做:

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?

推荐答案

Ruby抽象出整数的内部存储,因此您不必担心它。

Ruby abstracts away the internal storage of integers, so you don't have to worry about it.

如果为变量分配一个整数,Ruby将处理内部,在需要时分配内存。较小的整数类型为 Fixnum (存储在一个单词中),较大的整数是 Bignum

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 type Bignum.

a = 64
a.class  #=> Fixnum; stored in a single word
a += 1234567890
a.class  #=> Bignum; stored in more than a single word

Ruby是动态类型的,所以你不能强制变量只包含无符号8位整数(正如你不能强制变量只包含字符串值等)。

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中声明8位无符号整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆