Int16
Inherits Int / Comparable / Comparable / Comparable / Number / Comparable / Steppable / Comparable / Value / Object
Constants
Constructors
Returns a number for given digits and base.
The digits are expected as an Enumerable with the least significant digit as the first element.
Base must not be less than 2.
All digits must be within 0...base.
Int16.from_digits([5, 4, 3, 2, 1]) # => 12345
Int16.from_digits([4, 6, 6, 0, 5], base: 7) # => 12345
Int16.from_digits([45, 23, 1], base: 100) # => 12345
Int16.from_digits([1], base: -2) # raises ArgumentError
Int16.from_digits([-1]) # raises ArgumentError
Int16.from_digits([3], base: 2) # raises ArgumentError
Returns an Int16 by invoking to_i16 on value.
See String#to_i for more details.
Int16.new "20" # => 20
Int16.new " 20 ", whitespace: false # raises ArgumentError: Invalid Int16: " 20 "
Class methods
Instance methods
Returns true if self is not equal to other
or if self and other are unordered.
Returns true if self is not equal to other
or if self and other are unordered.
Returns the result of performing a bitwise AND of self's and other's bits.
Returns the result of performing a bitwise AND of self's and other's bits.
Returns the result of performing a bitwise AND of self's and other's bits.
Returns the result of performing a bitwise AND of self's and other's bits.
Returns the result of performing a bitwise AND of self's and other's bits.
Returns the result of performing a bitwise AND of self's and other's bits.
Returns the result of performing a bitwise AND of self's and other's bits.
Returns the result of performing a bitwise AND of self's and other's bits.
Returns the result of performing a bitwise AND of self's and other's bits.
Returns the result of performing a bitwise AND of self's and other's bits.
Returns the result of multiplying self and other.
In case of overflow a wrapping is performed.
Returns the result of multiplying self and other.
In case of overflow a wrapping is performed.
Returns the result of multiplying self and other.
In case of overflow a wrapping is performed.
Returns the result of multiplying self and other.
In case of overflow a wrapping is performed.
Returns the result of multiplying self and other.
In case of overflow a wrapping is performed.
Returns the result of multiplying self and other.
In case of overflow a wrapping is performed.
Returns the result of multiplying self and other.
In case of overflow a wrapping is performed.
Returns the result of multiplying self and other.
In case of overflow a wrapping is performed.
Returns the result of multiplying self and other.
In case of overflow a wrapping is performed.
Returns the result of multiplying self and other.
In case of overflow a wrapping is performed.
Returns the result of adding self and other.
In case of overflow a wrapping is performed.
Returns the result of adding self and other.
In case of overflow a wrapping is performed.
Returns the result of adding self and other.
In case of overflow a wrapping is performed.
Returns the result of adding self and other.
In case of overflow a wrapping is performed.
Returns the result of adding self and other.
In case of overflow a wrapping is performed.
Returns the result of adding self and other.
In case of overflow a wrapping is performed.
Returns the result of adding self and other.
In case of overflow a wrapping is performed.
Returns the result of adding self and other.
In case of overflow a wrapping is performed.
Returns the result of adding self and other.
In case of overflow a wrapping is performed.
Returns the result of adding self and other.
In case of overflow a wrapping is performed.
Returns the result of subtracting self and other.
In case of overflow a wrapping is performed.
Returns the result of subtracting self and other.
In case of overflow a wrapping is performed.
Returns the result of subtracting self and other.
In case of overflow a wrapping is performed.
Returns the result of subtracting self and other.
In case of overflow a wrapping is performed.
Returns the result of subtracting self and other.
In case of overflow a wrapping is performed.
Returns the result of subtracting self and other.
In case of overflow a wrapping is performed.
Returns the result of subtracting self and other.
In case of overflow a wrapping is performed.
Returns the result of subtracting self and other.
In case of overflow a wrapping is performed.
Returns the result of subtracting self and other.
In case of overflow a wrapping is performed.
Returns the result of subtracting self and other.
In case of overflow a wrapping is performed.
Returns the result of multiplying self and other.
Raises OverflowError in case of overflow.
Returns the result of multiplying self and other.
Raises OverflowError in case of overflow.
Returns the result of multiplying self and other.
Raises OverflowError in case of overflow.
Returns the result of multiplying self and other.
Raises OverflowError in case of overflow.
Returns the result of multiplying self and other.
Raises OverflowError in case of overflow.
Returns the result of multiplying self and other.
Raises OverflowError in case of overflow.
Returns the result of multiplying self and other.
Raises OverflowError in case of overflow.
Returns the result of multiplying self and other.
Raises OverflowError in case of overflow.
Returns the result of multiplying self and other.
Raises OverflowError in case of overflow.
Returns the result of multiplying self and other.
Raises OverflowError in case of overflow.
Returns the result of adding self and other.
Raises OverflowError in case of overflow.
Returns the result of adding self and other.
Raises OverflowError in case of overflow.
Returns the result of adding self and other.
Raises OverflowError in case of overflow.
Returns the result of adding self and other.
Raises OverflowError in case of overflow.
Returns the result of adding self and other.
Raises OverflowError in case of overflow.
Returns the result of adding self and other.
Raises OverflowError in case of overflow.
Returns the result of adding self and other.
Raises OverflowError in case of overflow.
Returns the result of adding self and other.
Raises OverflowError in case of overflow.
Returns the result of adding self and other.
Raises OverflowError in case of overflow.
Returns the result of adding self and other.
Raises OverflowError in case of overflow.
Returns the result of subtracting self and other.
Raises OverflowError in case of overflow.
Returns the result of subtracting self and other.
Raises OverflowError in case of overflow.
Returns the result of subtracting self and other.
Raises OverflowError in case of overflow.
Returns the result of subtracting self and other.
Raises OverflowError in case of overflow.
Returns the result of subtracting self and other.
Raises OverflowError in case of overflow.
Returns the result of subtracting self and other.
Raises OverflowError in case of overflow.
Returns the result of subtracting self and other.
Raises OverflowError in case of overflow.
Returns the result of subtracting self and other.
Raises OverflowError in case of overflow.
Returns the result of subtracting self and other.
Raises OverflowError in case of overflow.
Returns the result of subtracting self and other.
Raises OverflowError in case of overflow.
Returns the result of performing a bitwise XOR of self's and other's bits.
Returns the result of performing a bitwise XOR of self's and other's bits.
Returns the result of performing a bitwise XOR of self's and other's bits.
Returns the result of performing a bitwise XOR of self's and other's bits.
Returns the result of performing a bitwise XOR of self's and other's bits.
Returns the result of performing a bitwise XOR of self's and other's bits.
Returns the result of performing a bitwise XOR of self's and other's bits.
Returns the result of performing a bitwise XOR of self's and other's bits.
Returns the result of performing a bitwise XOR of self's and other's bits.
Returns the result of performing a bitwise XOR of self's and other's bits.
Returns the result of performing a bitwise OR of self's and other's bits.
Returns the result of performing a bitwise OR of self's and other's bits.
Returns the result of performing a bitwise OR of self's and other's bits.
Returns the result of performing a bitwise OR of self's and other's bits.
Returns the result of performing a bitwise OR of self's and other's bits.
Returns the result of performing a bitwise OR of self's and other's bits.
Returns the result of performing a bitwise OR of self's and other's bits.
Returns the result of performing a bitwise OR of self's and other's bits.
Returns the result of performing a bitwise OR of self's and other's bits.
Returns the result of performing a bitwise OR of self's and other's bits.
Returns the absolute value of self as an unsigned value of the same size.
Returns self if self is already an Int::Unsigned. This method never
overflows.
1_u32.abs_unsigned # => 1_u32
2_i32.abs_unsigned # => 2_u32
-3_i8.abs_unsigned # => 3_u8
Int16::MIN.abs_unsigned # => 32768_u16
Reverses the bits of self; the least significant bit becomes the most
significant, and vice-versa.
0b01001011_u8.bit_reverse # => 0b11010010
0b1100100001100111_u16.bit_reverse # => 0b1110011000010011
Swaps the bytes of self; a little-endian value becomes a big-endian value,
and vice-versa. The bit order within each byte is unchanged.
Has no effect on 8-bit integers.
0x1234_i16.byte_swap # => 0x3412
Returns the negative of self as a signed value of the same size.
Returns -self if self is already an Int::Signed. Raises
OverflowError in case of overflow.
1_i32.neg_signed # => -1_i32
2_u16.neg_signed # => -2_i16
128_u8.neg_signed # => -128_i8
Int16::MIN.neg_signed # raises OverflowError
Counts 1-bits in the binary representation of this integer.
5.popcount # => 2
-15.popcount # => 29
Returns the bitwise rotation of self n times in the most significant
bit's direction. Negative shifts are equivalent to rotate_right(-n).
0b01001101_u8.rotate_left(3) # => 0b01101010
0b01001101_u8.rotate_left(8) # => 0b01001101
0b01001101_u8.rotate_left(11) # => 0b01101010
0b01001101_u8.rotate_left(-1) # => 0b10100110
Returns the bitwise rotation of self n times in the least significant
bit's direction. Negative shifts are equivalent to rotate_left(-n).
0b01001101_u8.rotate_right(3) # => 0b10101001
0b01001101_u8.rotate_right(8) # => 0b01001101
0b01001101_u8.rotate_right(11) # => 0b10101001
0b01001101_u8.rotate_right(-1) # => 0b10011010
Returns self converted to a signed value of the same size.
Simply returns self unmodified if self is already an Int::Signed.
Raises OverflowError in case of overflow.
1_u32.to_signed # => 1_i32
2_u16.to_signed # => 2_i16
3_i64.to_signed # => 3_i64
Returns self converted to a signed value of the same size, wrapping in
case of overflow.
Simply returns self unmodified if self is already an Int::Signed.
1_u32.to_signed! # => 1_i32
65530_u16.to_signed! # => -6_i16
3_i64.to_signed! # => 3_i64
Returns self converted to an unsigned value of the same size.
Simply returns self unmodified if self is already an Int::Unsigned.
Raises OverflowError in case of overflow.
1_i32.to_unsigned # => 1_u32
2_i16.to_unsigned # => 2_u16
3_u64.to_unsigned # => 3_u64
Returns self converted to an unsigned value of the same size, wrapping in
case of overflow.
Simply returns self unmodified if self is already an Int::Unsigned.
1_i32.to_unsigned! # => 1_u32
(-6_i16).to_unsigned! # => 65530_u16
3_u64.to_unsigned! # => 3_u64
Returns a Char that has the unicode codepoint of self,
without checking if this integer is in the range valid for
chars (0..0xd7ff and 0xe000..0x10ffff). In case of overflow
a wrapping is performed.
You should never use this method unless chr turns out to
be a bottleneck.
97.unsafe_chr # => 'a'