class Integer
Public Instance Methods
Arithmetic right-shift of the low 16 bits in this integer.
If bit 16 is a 1, the vacated bit positions will be filled with 1s. Otherwise, they will be filled with 0s. Or, if the shift distance is negative, a left shift will be performed instead, and the vacated bit positions will be filled with 0s.
@example
0xaabbccdd.arith_rshift16(1).to_s(16) # => "aabbe66e" 0xaabbccdd.arith_rshift16(2).to_s(16) # => "aabbf337"
@param shiftdist [Integer] Number of bit positions to shift by @return [Integer]
Arithmetic right-shift of the low 32 bits in this integer.
If bit 32 is a 1, the vacated bit positions will be filled with 1s. Otherwise, they will be filled with 0s. Or, if the shift distance is negative, a left shift will be performed instead, and the vacated bit positions will be filled with 0s.
@example
0xaabbccddaabbccdd.arith_rshift32(1).to_s(16) # => "d55de66e" 0xaabbccddaabbccdd.arith_rshift32(2).to_s(16) # => "eaaef337"
@param shiftdist [Integer] Number of bit positions to shift by @return [Integer]
Arithmetic right-shift of the low 64 bits in this integer.
If bit 64 is a 1, the vacated bit positions will be filled with 1s. Otherwise, they will be filled with 0s. Or, if the shift distance is negative, a left shift will be performed instead, and the vacated bit positions will be filled with 0s.
@example
0xaabbccddaabbccdd.arith_rshift64(1).to_s(16) # => "d55de66ed55de66e" 0xaabbccddaabbccdd.arith_rshift64(2).to_s(16) # => "eaaef3376aaef337"
@param shiftdist [Integer] Number of bit positions to shift by @return [Integer]
Arithmetic right-shift of the low 8 bits in this integer.
If bit 8 is a 1, the vacated bit positions will be filled with 1s. Otherwise, they will be filled with 0s. Or, if the shift distance is negative, a left shift will be performed instead, and the vacated bit positions will be filled with 0s.
@example
0xaabbccdd.arith_rshift8(1).to_s(16) # => "aabbccee" 0xaabbccdd.arith_rshift8(2).to_s(16) # => "aabbccf7"
@param shiftdist [Integer] Number of bit positions to shift by @return [Integer]
Reverse the low 16 bits in this integer.
If the receiver is negative, raise ‘RangeError`.
@example
0b0110101100001011.bitreverse16.to_s(2) # => "1101000011010110"
@return [Integer]
Reverse the low 32 bits in this integer.
If the receiver is negative, raise ‘RangeError`.
@example
0x12341234.bitreverse32.to_s(16) # => "2c482c48"
@return [Integer]
Reverse the low 64 bits in this integer.
If the receiver is negative, raise ‘RangeError`.
@example
0xabcd1234abcd1234.bitreverse64.to_s(16) # => "2c48b3d52c48b3d5"
@return [Integer]
Reverse the low 8 bits in this integer.
If the receiver is negative, raise ‘RangeError`.
@example
0b01101011.bitreverse8.to_s(2) # => "11010110"
@return [Integer]
Reverse the least-significant and second least-significant bytes of this integer.
If the receiver is negative, raise ‘RangeError`.
@example
0xFF00.bswap16 # => 255 0x00FF.bswap16 # => 65280
@return [Integer]
Reverse the least-significant 4 bytes of this integer.
Does not reverse bits within each byte. This can be used to swap endianness of a 32-bit integer. If the receiver is negative, raise ‘RangeError`.
@example
0xaabbccdd.bswap32.to_s(16) # => "ddccbbaa"
@return [Integer]
Reverse the least-significant 8 bytes of this integer.
Does not reverse bits within each byte. This can be used to swap endianness of a 64-bit integer. If the receiver is negative, raise ‘RangeError`.
@example
0xaabbccdd.bswap64.to_s(16) # => "ddccbbaa00000000"
@return [Integer]
Return the index of the highest 1 bit, where the least-significant bit is index 1.
If the receiver is 0, return 0.
If the receiver is negative, raise ‘RangeError`.
@example
1.hi_bit # => 1 255.hi_bit # => 8
@return [Integer]
Return the index of the lowest 1 bit, where the least-significant bit is index 1.
If the receiver is 0, return 0.
If the receiver is negative, raise ‘RangeError`.
@example
1.lo_bit # => 1 128.lo_bit # => 8
@return [Integer]
Left-rotation ("circular shift") of the low 16 bits in this integer.
If the rotate distance is negative, the bit rotation will be to the right instead.
@example
0b0111000101110001.lrot16(1).to_s(2) # => "1110001011100010" 0b0111000101110001.lrot16(3).to_s(2) # => "1000101110001011"
@param rotdist [Integer] Number of bit positions to rotate by @return [Integer]
Left-rotation ("circular shift") of the low 32 bits in this integer.
If the rotate distance is negative, the bit rotation will be to the right instead.
@example
0xaabbccdd.lrot32(4).to_s(16) # => "abbccdda"
@param rotdist [Integer] Number of bit positions to rotate by @return [Integer]
Left-rotation ("circular shift") of the low 64 bits in this integer.
If the rotate distance is negative, the bit rotation will be to the right instead.
@example
0x11223344aabbccdd.lrot64(4).to_s(16) # => "1223344aabbccdd1"
@param rotdist [Integer] Number of bit positions to rotate by @return [Integer]
Left-rotation ("circular shift") of the low 8 bits in this integer.
If the rotate distance is negative, the bit rotation will be to the right instead.
@example
0b01110001.lrot8(1).to_s(2) # => "11100010" 0b01110001.lrot8(3).to_s(2) # => "10001011"
@param rotdist [Integer] Number of bit positions to rotate by @return [Integer]
Left-shift of the low 16 bits in this integer.
If the shift distance is negative, a right shift will be performed instead. The vacated bit positions will be filled with 0 bits. If shift distance is more than 15 or less than -15, the low 16 bits will all be zeroed.
@example
0x11223344.lshift16(1).to_s(16) # => "11226688" 0x11223344.lshift16(2).to_s(16) # => "1122cd10"
@param shiftdist [Integer] Number of bit positions to shift by @return [Integer]
Left-shift of the low 32 bits in this integer.
If the shift distance is negative, a right shift will be performed instead. The vacated bit positions will be filled with 0 bits. If shift distance is more than 31 or less than -31, the low 32 bits will all be zeroed.
@example
0x11223344.lshift32(1).to_s(16) # => "22446688" 0x11223344.lshift32(2).to_s(16) # => "4488cd10"
@param shiftdist [Integer] Number of bit positions to shift by @return [Integer]
Left-shift of the low 64 bits in this integer.
If the shift distance is negative, a right shift will be performed instead. The vacated bit positions will be filled with 0 bits. If shift distance is more than 63 or less than -63, the low 64 bits will all be zeroed.
@example
0x1122334411223344.lshift64(1).to_s(16) # => "2244668822446688" 0x1122334411223344.lshift64(2).to_s(16) # => "4488cd104488cd10"
@param shiftdist [Integer] Number of bit positions to shift by @return [Integer]
Left-shift of the low 8 bits in this integer.
If the shift distance is negative, a right shift will be performed instead. The vacated bit positions will be filled with 0 bits. If shift distance is more than 7 or less than -7, the low 8 bits will all be zeroed.
@example
0x11223344.lshift8(1).to_s(16) # => "11223388" 0x11223344.lshift8(2).to_s(16) # => "11223310"
@param shiftdist [Integer] Number of bit positions to shift by @return [Integer]
Return the number of 1 bits in this integer.
If the receiver is negative, raise ‘RangeError`.
@example
7.popcount # => 3 255.popcount # => 8
@return [Integer]
Right-rotation ("circular shift") of the low 16 bits in this integer.
If the rotate distance is negative, the bit rotation will be to the left instead.
@example
0b0111000101110001.rrot16(1).to_s(2) # => "1011100010111000" 0b0111000101110001.rrot16(3).to_s(2) # => "10111000101110"
@param rotdist [Integer] Number of bit positions to rotate by @return [Integer]
Right-rotation ("circular shift") of the low 32 bits in this integer.
If the rotate distance is negative, the bit rotation will be to the left instead.
@example
0xaabbccdd.rrot32(4).to_s(16) # => "daabbccd"
@param rotdist [Integer] Number of bit positions to rotate by @return [Integer]
Right-rotation ("circular shift") of the low 64 bits in this integer.
If the rotate distance is negative, the bit rotation will be to the left instead.
@example
0x11223344aabbccdd.rrot64(4).to_s(16) # => "d11223344aabbccd"
@param rotdist [Integer] Number of bit positions to rotate by @return [Integer]
Right-rotation ("circular shift") of the low 8 bits in this integer.
If the rotate distance is negative, the bit rotation will be to the left instead.
@example
0b01110001.rrot8(1).to_s(2) # => "10111000" 0b01110001.rrot8(3).to_s(2) # => "101110"
@param rotdist [Integer] Number of bit positions to rotate by @return [Integer]
Right-shift of the low 16 bits in this integer.
If the shift distance is negative, a left shift will be performed instead. The vacated bit positions will be filled with 0 bits. If shift distance is more than 15 or less than -15, the low 16 bits will all be zeroed.
@example
0x11223344.rshift16(1).to_s(16) # => "112219a2" 0x11223344.rshift16(2).to_s(16) # => "11220cd1"
@param shiftdist [Integer] Number of bit positions to shift by @return [Integer]
Right-shift of the low 32 bits in this integer.
If the shift distance is negative, a left shift will be performed instead. The vacated bit positions will be filled with 0 bits. If shift distance is more than 31 or less than -31, the low 32 bits will all be zeroed.
@example
0x11223344.rshift32(1).to_s(16) # => "89119a2" 0x11223344.rshift32(2).to_s(16) # => "4488cd1"
@param shiftdist [Integer] Number of bit positions to shift by @return [Integer]
Right-shift of the low 64 bits in this integer.
If the shift distance is negative, a left shift will be performed instead. The vacated bit positions will be filled with 0 bits. If shift distance is more than 63 or less than -63, the low 64 bits will all be zeroed.
@example
0x1122334411223344.rshift64(1).to_s(16) # => "89119a2089119a2" 0x1122334411223344.rshift64(2).to_s(16) # => "4488cd104488cd1"
@param shiftdist [Integer] Number of bit positions to shift by @return [Integer]
Right-shift of the low 8 bits in this integer.
If the shift distance is negative, a left shift will be performed instead. The vacated bit positions will be filled with 0 bits. If shift distance is more than 7 or less than -7, the low 8 bits will all be zeroed.
@example
0x11223344.rshift8(1).to_s(16) # => "11223322" 0x11223344.rshift8(2).to_s(16) # => "11223311"
@param shiftdist [Integer] Number of bit positions to shift by @return [Integer]