jsanders-bitfields 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/bits.rb +6 -3
  2. metadata +1 -1
data/lib/bits.rb CHANGED
@@ -13,7 +13,10 @@ class Bits
13
13
  end
14
14
 
15
15
  def +(bits)
16
- Bits.new("0b#{@bits}" + bit_string_from_input(bits))
16
+ bit_string_to_concat = bit_string_from_input(bits)
17
+ length = @bits.length + bit_string_to_concat.length
18
+ string = "0b#{@bits}#{bit_string_to_concat}"
19
+ Bits.new(string, length)
17
20
  end
18
21
 
19
22
  def bit_string
@@ -21,11 +24,11 @@ class Bits
21
24
  end
22
25
 
23
26
  def hex_string
24
- @bits.to_i(2).to_s(16)
27
+ "%0#{(@bits.length / 4) + (@bits.length % 4)}x" % @bits.to_i(2)
25
28
  end
26
29
 
27
30
  def oct_string
28
- @bits.to_i(2).to_s(8)
31
+ "%0#{(bit_string.length / 3) + (bit_string.length % 3)}o" % bit_string.to_i(2)
29
32
  end
30
33
 
31
34
  def integer
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsanders-bitfields
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Sanders