Module: Integer::IntegerExtensions
- Included in:
- Integer
- Defined in:
- lib/ruckus/extensions/integer.rb
Instance Method Summary collapse
- #ffs ⇒ Object
-
#to_b(pre = "") ⇒ Object
Print a number in binary.
- #to_b16 ⇒ Object
- #to_b32 ⇒ Object
-
#to_hex(pre = "0x") ⇒ Object
Print a number in hex.
- #to_l16 ⇒ Object
-
#to_l32 ⇒ Object
Convert integers to binary strings.
- #to_u8 ⇒ Object
Instance Method Details
#ffs ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/ruckus/extensions/integer.rb', line 16 def ffs i = 0 v = self while((v >>= 1) != 0) i += 1 end return i end |
#to_b(pre = "") ⇒ Object
Print a number in binary
14 |
# File 'lib/ruckus/extensions/integer.rb', line 14 def to_b(pre=""); pre + to_s(2); end |
#to_b16 ⇒ Object
7 |
# File 'lib/ruckus/extensions/integer.rb', line 7 def to_b16; [self].pack "n"; end |
#to_b32 ⇒ Object
5 |
# File 'lib/ruckus/extensions/integer.rb', line 5 def to_b32; [self].pack "N"; end |
#to_hex(pre = "0x") ⇒ Object
Print a number in hex
11 |
# File 'lib/ruckus/extensions/integer.rb', line 11 def to_hex(pre="0x"); pre + to_s(16); end |
#to_l16 ⇒ Object
6 |
# File 'lib/ruckus/extensions/integer.rb', line 6 def to_l16; [self].pack "v"; end |
#to_l32 ⇒ Object
Convert integers to binary strings
4 |
# File 'lib/ruckus/extensions/integer.rb', line 4 def to_l32; [self].pack "L"; end |
#to_u8 ⇒ Object
8 |
# File 'lib/ruckus/extensions/integer.rb', line 8 def to_u8; [self].pack "C"; end |