るりまサーチ

最速Rubyリファレンスマニュアル検索!
866件ヒット [1-100件を表示] (0.029秒)
トップページ > クエリ:ruby[x] > クラス:Integer[x]

別のキーワード

  1. rbconfig ruby
  2. fiddle ruby_free
  3. fiddle build_ruby_platform
  4. rake ruby
  5. rubygems/defaults ruby_engine

ライブラリ

キーワード

検索結果

<< 1 2 3 ... > >>

Integer#[](nth) -> Integer (19.0)

nth 番目のビット(最下位ビット(LSB)が 0 番目)が立っている時 1 を、そうでなければ 0 を返します。

...lf[..j] で n & ((1 << (j + 1)) - 1) が 0 以外のとき
@raise ArgumentError self[...j] で n & ((1 << j) - 1) が 0 以外のとき

//emlist[][ruby]{
a = 0b11001100101010
30.downto(0) {|n| print a[n] }
# => 0000000000000000011001100101010

a = 9**15
50.downto(0) {|n| print a[n] }
# => 000101110...
...01
//}

n[i] は (n >> i) & 1 と等価なので、負のインデックスは常に 0 を返します。

//emlist[][ruby]{
p 255[-1] # => 0
//}

//emlist[複数ビットの例][ruby]{
0b01001101[2, 4] #=> 0b0011
0b01001100[2..5] #=> 0b0011
0b01001100[2...6] #=> 0b0011
# ^^^^
//}

self[nth]=bit...

Integer#[](nth, len) -> Integer (19.0)

nth 番目のビット(最下位ビット(LSB)が 0 番目)が立っている時 1 を、そうでなければ 0 を返します。

...lf[..j] で n & ((1 << (j + 1)) - 1) が 0 以外のとき
@raise ArgumentError self[...j] で n & ((1 << j) - 1) が 0 以外のとき

//emlist[][ruby]{
a = 0b11001100101010
30.downto(0) {|n| print a[n] }
# => 0000000000000000011001100101010

a = 9**15
50.downto(0) {|n| print a[n] }
# => 000101110...
...01
//}

n[i] は (n >> i) & 1 と等価なので、負のインデックスは常に 0 を返します。

//emlist[][ruby]{
p 255[-1] # => 0
//}

//emlist[複数ビットの例][ruby]{
0b01001101[2, 4] #=> 0b0011
0b01001100[2..5] #=> 0b0011
0b01001100[2...6] #=> 0b0011
# ^^^^
//}

self[nth]=bit...

Integer#[](range) -> Integer (19.0)

nth 番目のビット(最下位ビット(LSB)が 0 番目)が立っている時 1 を、そうでなければ 0 を返します。

...lf[..j] で n & ((1 << (j + 1)) - 1) が 0 以外のとき
@raise ArgumentError self[...j] で n & ((1 << j) - 1) が 0 以外のとき

//emlist[][ruby]{
a = 0b11001100101010
30.downto(0) {|n| print a[n] }
# => 0000000000000000011001100101010

a = 9**15
50.downto(0) {|n| print a[n] }
# => 000101110...
...01
//}

n[i] は (n >> i) & 1 と等価なので、負のインデックスは常に 0 を返します。

//emlist[][ruby]{
p 255[-1] # => 0
//}

//emlist[複数ビットの例][ruby]{
0b01001101[2, 4] #=> 0b0011
0b01001100[2..5] #=> 0b0011
0b01001100[2...6] #=> 0b0011
# ^^^^
//}

self[nth]=bit...

Integer#**(other) -> Numeric (13.0)

算術演算子。冪(べき乗)を計算します。

...します。
@return 計算結果
@raise TypeError 2引数 pow で Integer 以外を指定した場合に発生します。
@raise RangeError 2引数 pow で other に負の数を指定した場合に発生します。

//emlist[][ruby]{
2 ** 3 # => 8
2 ** 0 # => 1
0 ** 0 # => 1
3.pow(3, 8) # =>...
...になりそうなとき、警告を出したうえで Float::INFINITY を返します。

//emlist[計算を放棄して Float::INFINITY を返す例][ruby]{
p 100**9999999
# => warning: in a**b, b may be too big
# Infinity
//}

判定の閾値は変わりえます。


@see BigDecimal#power...
...eError 2引数 pow で Integer 以外を指定した場合に発生します。
@raise RangeError 2引数 pow で other に負の数を指定した場合に発生します。
@raise ArgumentError 計算結果が巨大になりすぎる場合に発生します。

//emlist[][ruby]{
2 ** 3 # => 8
2 **...
...> -3
5.pow(2, -8) # => -7
//}


計算結果が巨大すぎるときは ArgumentError が発生します。

//emlist[計算結果が巨大すぎる例][ruby]{
p 100**9999999999999999999
# => exponent is too large (ArgumentError)
//}

判定の閾値は変わりえます。

@see BigDecimal#power...

Integer#[](nth) -> Integer (13.0)

nth 番目のビット(最下位ビット(LSB)が 0 番目)が立っている時 1 を、そうでなければ 0 を返します。

...ている時 1
を、そうでなければ 0 を返します。

@param nth 何ビット目を指すかの数値
@return 1 か 0

//emlist[][ruby]{
a = 0b11001100101010
30.downto(0) {|n| print a[n] }
# => 0000000000000000011001100101010

a = 9**15
50.downto(0) {|n| print a[n] }
# => 0001011101...
...11000011110010100111100010111001
//}

n[i] は (n >> i) & 1 と等価なので、負のインデックスは常に 0 を返します。

//emlist[][ruby]{
p 255[-1] # => 0
//}


self[nth]=bit (つまりビットの修正) がないのは、Numeric 関連クラスが
immutable であるためです...

絞り込み条件を変える

Integer#chr -> String (13.0)

self を文字コードとして見た時に、引数で与えたエンコーディング encoding に対応する文字を返します。

...f を文字コードとして見た時に、引数で与えたエンコーディング encoding に対応する文字を返します。

//emlist[][ruby]{
p 65.chr
# => "A"
p 12354.chr
# => `chr': 12354 out of char range (RangeError)

p 12354.chr(Encoding::UTF_8)
# => "あ"
p 12354.chr(Encoding::EUC...
...れた場合は self を US-ASCII、ASCII-8BIT、デフォルト内部エンコーディングの順で優先的に解釈します。

//emlist[][ruby]{
p 0x79.chr.encoding # => #<Encoding:US_ASCII>
p 0x80.chr.encoding # => #<Encoding:ASCII_8BIT>
//}

@param encoding エンコーディングを表...

Integer#chr(encoding) -> String (13.0)

self を文字コードとして見た時に、引数で与えたエンコーディング encoding に対応する文字を返します。

...f を文字コードとして見た時に、引数で与えたエンコーディング encoding に対応する文字を返します。

//emlist[][ruby]{
p 65.chr
# => "A"
p 12354.chr
# => `chr': 12354 out of char range (RangeError)

p 12354.chr(Encoding::UTF_8)
# => "あ"
p 12354.chr(Encoding::EUC...
...れた場合は self を US-ASCII、ASCII-8BIT、デフォルト内部エンコーディングの順で優先的に解釈します。

//emlist[][ruby]{
p 0x79.chr.encoding # => #<Encoding:US_ASCII>
p 0x80.chr.encoding # => #<Encoding:ASCII_8BIT>
//}

@param encoding エンコーディングを表...

Integer#digits -> [Integer] (13.0)

base を基数として self を位取り記数法で表記した数値を配列で返します。 base を指定しない場合の基数は 10 です。

...い場合の基数は 10 です。

//emlist[][ruby]{
16.digits # => [6, 1]
16.digits(16) # => [0, 1]
//}

self は非負整数でなければいけません。非負整数でない場合は、Math::DomainErrorが発生します。

//emlist[][ruby]{
-10.digits # Math::DomainError: out of domai...

Integer#digits(base) -> [Integer] (13.0)

base を基数として self を位取り記数法で表記した数値を配列で返します。 base を指定しない場合の基数は 10 です。

...い場合の基数は 10 です。

//emlist[][ruby]{
16.digits # => [6, 1]
16.digits(16) # => [0, 1]
//}

self は非負整数でなければいけません。非負整数でない場合は、Math::DomainErrorが発生します。

//emlist[][ruby]{
-10.digits # Math::DomainError: out of domai...

Integer#gcd(n) -> Integer (13.0)

自身と整数 n の最大公約数を返します。

...//emlist[][ruby]{
2.gcd(2) # => 2
3.gcd(7) # => 1
3.gcd(-7) # => 1
((1<<31)-1).gcd((1<<61)-1) # => 1
//}

また、self や n が 0 だった場合は、0 ではない方の整数の絶対値を返します。

//emlist[][ruby]{
3.gcd(0)...
...# => 3
0.gcd(-7) # => 7
//}

@see Integer#lcm, Integer#gcdlcm...

絞り込み条件を変える

Integer#lcm(n) -> Integer (13.0)

自身と整数 n の最小公倍数を返します。

...と発生します。

//emlist[][ruby]{
2.lcm(2) # => 2
3.lcm(-7) # => 21
((1<<31)-1).lcm((1<<61)-1) # => 4951760154835678088235319297
//}

また、self や n が 0 だった場合は、0 を返します。

//emlist[][ruby]{
3.lcm(0) # => 0...
...0.lcm(-7) # => 0
//}

@see Integer#gcd, Integer#gcdlcm...
<< 1 2 3 ... > >>