Class: Integer
- Inherits:
-
Object
- Object
- Integer
- Defined in:
- ext/bit_twiddle/bit_twiddle.c
Overview
Ruby’s good old Integer.
‘require “bit-twiddle/core_ext”` before trying to use any of the below methods.
Instance Method Summary collapse
-
#arith_rshift16 ⇒ Integer
Arithmetic right-shift of the low 16 bits in this integer.
-
#arith_rshift32 ⇒ Integer
Arithmetic right-shift of the low 32 bits in this integer.
-
#arith_rshift64 ⇒ Integer
Arithmetic right-shift of the low 64 bits in this integer.
-
#arith_rshift8 ⇒ Integer
Arithmetic right-shift of the low 8 bits in this integer.
-
#bitreverse16 ⇒ Integer
Reverse the low 16 bits in this integer.
-
#bitreverse32 ⇒ Integer
Reverse the low 32 bits in this integer.
-
#bitreverse64 ⇒ Integer
Reverse the low 64 bits in this integer.
-
#bitreverse8 ⇒ Integer
Reverse the low 8 bits in this integer.
-
#bswap16 ⇒ Integer
Reverse the least-significant and second least-significant bytes of this integer.
-
#bswap32 ⇒ Integer
Reverse the least-significant 4 bytes of this integer.
-
#bswap64 ⇒ Integer
Reverse the least-significant 8 bytes of this integer.
-
#hi_bit ⇒ Integer
Return the index of the highest 1 bit, where the least-significant bit is index 1.
-
#lo_bit ⇒ Integer
Return the index of the lowest 1 bit, where the least-significant bit is index 1.
-
#lrot16 ⇒ Integer
Left-rotation (“circular shift”) of the low 16 bits in this integer.
-
#lrot32 ⇒ Integer
Left-rotation (“circular shift”) of the low 32 bits in this integer.
-
#lrot64 ⇒ Integer
Left-rotation (“circular shift”) of the low 64 bits in this integer.
-
#lrot8 ⇒ Integer
Left-rotation (“circular shift”) of the low 8 bits in this integer.
-
#lshift16 ⇒ Integer
Left-shift of the low 16 bits in this integer.
-
#lshift32 ⇒ Integer
Left-shift of the low 32 bits in this integer.
-
#lshift64 ⇒ Integer
Left-shift of the low 64 bits in this integer.
-
#lshift8 ⇒ Integer
Left-shift of the low 8 bits in this integer.
-
#popcount ⇒ Integer
Return the number of 1 bits in this integer.
-
#rrot16 ⇒ Integer
Right-rotation (“circular shift”) of the low 16 bits in this integer.
-
#rrot32 ⇒ Integer
Right-rotation (“circular shift”) of the low 32 bits in this integer.
-
#rrot64 ⇒ Integer
Right-rotation (“circular shift”) of the low 64 bits in this integer.
-
#rrot8 ⇒ Integer
Right-rotation (“circular shift”) of the low 8 bits in this integer.
-
#rshift16 ⇒ Integer
Right-shift of the low 16 bits in this integer.
-
#rshift32 ⇒ Integer
Right-shift of the low 32 bits in this integer.
-
#rshift64 ⇒ Integer
Right-shift of the low 64 bits in this integer.
-
#rshift8 ⇒ Integer
Right-shift of the low 8 bits in this integer.
Instance Method Details
#arith_rshift16 ⇒ Integer
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.
#arith_rshift32 ⇒ 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.
#arith_rshift64 ⇒ 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.
#arith_rshift8 ⇒ 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.
#bitreverse16 ⇒ Integer
Reverse the low 16 bits in this integer.
If the receiver is negative, raise ‘RangeError`.
#bitreverse32 ⇒ Integer
Reverse the low 32 bits in this integer.
If the receiver is negative, raise ‘RangeError`.
#bitreverse64 ⇒ Integer
Reverse the low 64 bits in this integer.
If the receiver is negative, raise ‘RangeError`.
#bitreverse8 ⇒ Integer
Reverse the low 8 bits in this integer.
If the receiver is negative, raise ‘RangeError`.
#bswap16 ⇒ Integer
Reverse the least-significant and second least-significant bytes of this integer.
If the receiver is negative, raise ‘RangeError`.
#bswap32 ⇒ 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`.
#bswap64 ⇒ 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`.
#hi_bit ⇒ 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`.
#lo_bit ⇒ 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`.
#lrot16 ⇒ 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.
#lrot32 ⇒ 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.
#lrot64 ⇒ 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.
#lrot8 ⇒ 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.
#lshift16 ⇒ 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.
#lshift32 ⇒ 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.
#lshift64 ⇒ 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.
#lshift8 ⇒ 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.
#popcount ⇒ Integer
Return the number of 1 bits in this integer.
If the receiver is negative, raise ‘RangeError`.
#rrot16 ⇒ 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.
#rrot32 ⇒ 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.
#rrot64 ⇒ 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.
#rrot8 ⇒ 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.
#rshift16 ⇒ 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.
#rshift32 ⇒ 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.
#rshift64 ⇒ 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.
#rshift8 ⇒ 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.