Module: Integer::IntegerExtensions
- Included in:
- Integer
- Defined in:
- lib/ragweed/utils.rb
Instance Method Summary collapse
- #ffs ⇒ Object
- #sx16 ⇒ Object
- #sx32 ⇒ Object
-
#sx8 ⇒ Object
sign extend.
- #to_b16 ⇒ Object
- #to_b32 ⇒ Object
- #to_l16 ⇒ Object
-
#to_l32 ⇒ Object
Convert integers to binary strings.
- #to_u8 ⇒ Object
Instance Method Details
#ffs ⇒ Object
145 146 147 148 149 150 151 152 |
# File 'lib/ragweed/utils.rb', line 145 def ffs i = 0 v = self while((v >>= 1) != 0) i += 1 end return i end |
#sx16 ⇒ Object
142 |
# File 'lib/ragweed/utils.rb', line 142 def sx16; ([self].pack "s").unpack("S").first; end |
#sx32 ⇒ Object
143 |
# File 'lib/ragweed/utils.rb', line 143 def sx32; ([self].pack "l").unpack("L").first; end |
#sx8 ⇒ Object
sign extend
141 |
# File 'lib/ragweed/utils.rb', line 141 def sx8; ([self].pack "c").unpack("C").first; end |
#to_b16 ⇒ Object
137 |
# File 'lib/ragweed/utils.rb', line 137 def to_b16; [self].pack "n"; end |
#to_b32 ⇒ Object
135 |
# File 'lib/ragweed/utils.rb', line 135 def to_b32; [self].pack "N"; end |
#to_l16 ⇒ Object
136 |
# File 'lib/ragweed/utils.rb', line 136 def to_l16; [self].pack "v"; end |
#to_l32 ⇒ Object
Convert integers to binary strings
134 |
# File 'lib/ragweed/utils.rb', line 134 def to_l32; [self].pack "L"; end |
#to_u8 ⇒ Object
138 |
# File 'lib/ragweed/utils.rb', line 138 def to_u8; [self].pack "C"; end |