jsanders-bitfields 0.2.6 → 0.2.8

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 +8 -0
  2. metadata +2 -2
data/lib/bits.rb CHANGED
@@ -35,6 +35,14 @@ class Bits
35
35
  @bits.to_i(2)
36
36
  end
37
37
 
38
+ def signed_integer
39
+ length_of_unsigned = @length - 1
40
+ highest_unsigned = 2 ** length_of_unsigned
41
+ sign_bit = (integer >> length_of_unsigned) & 1
42
+ unsigned_portion = integer & (highest_unsigned - 1)
43
+ (sign_bit == 1) ? -(highest_unsigned - unsigned_portion) : unsigned_portion
44
+ end
45
+
38
46
  def set(bits)
39
47
  @bits = bit_string_from_input(bits, @length)
40
48
  end
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.6
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Sanders
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-23 00:00:00 -08:00
12
+ date: 2009-02-26 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15