bitint 0.5.0 → 0.5.1
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.
- checksums.yaml +4 -4
- data/lib/bitint/bitint.rb +51 -54
- data/lib/bitint/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e690f5f11cfde4a4dce6c24ba3ab3257c8785fafff6d5ec704ed8e00399af273
|
4
|
+
data.tar.gz: 48145ab578471740f982c95b351d0c1ebf6f9cd764f058ef574e35634f5e2224
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 062c4a993dd220775779555dd65bbe334a1b460533b76e59aec831994c3272be09897ce4c5711ae1585907f45c050eb8288eb1771a01db2c19aa032dc7d927b6
|
7
|
+
data.tar.gz: 3a48c9aae6a186c2057fe4f8ee4f4e88576084a6148c29cbc316de7d4c29db849ea9935a21ecb8dd2c1b62752b02110f2a16d55a2745f330c2a282c7da93033e
|
data/lib/bitint/bitint.rb
CHANGED
@@ -211,25 +211,6 @@ class BitInt < Numeric
|
|
211
211
|
# Modulos +self+ by +rhs+.
|
212
212
|
def %(rhs) = self.class.new(@int % rhs.to_i)
|
213
213
|
|
214
|
-
# Raises +self+ to the +rhs+th power.
|
215
|
-
# Note that `Numeric` only defines `.to_int` (not `.to_i`)
|
216
|
-
def **(rhs) = self.class.new((@int ** rhs.to_i).to_int)
|
217
|
-
|
218
|
-
# Shifts +self+ left by +rhs+ bits.
|
219
|
-
def <<(rhs) = self.class.new(@int << rhs.to_i)
|
220
|
-
|
221
|
-
# Shifts +self+ right by +rhs+ bits.
|
222
|
-
def >>(rhs) = self.class.new(@int >> rhs.to_i)
|
223
|
-
|
224
|
-
# Bitwise ANDs +self+ and +rhs+.
|
225
|
-
def &(rhs) = self.class.new(@int & rhs.to_i)
|
226
|
-
|
227
|
-
# Bitwise ORs +self+ and +rhs+.
|
228
|
-
def |(rhs) = self.class.new(@int | rhs.to_i)
|
229
|
-
|
230
|
-
# Bitwise XORs +self+ and +rhs+.
|
231
|
-
def ^(rhs) = self.class.new(@int ^ rhs.to_i)
|
232
|
-
|
233
214
|
# :section:
|
234
215
|
|
235
216
|
# Returns whether +self+ is a positive integer. Zero is not positive.
|
@@ -254,6 +235,27 @@ class BitInt < Numeric
|
|
254
235
|
# :section: Bit-level operations #
|
255
236
|
##################################
|
256
237
|
|
238
|
+
# Raises +self+ to the +rhs+th power.
|
239
|
+
#--
|
240
|
+
# Note that `Numeric` only defines `.to_int` (not `.to_i`)
|
241
|
+
#++
|
242
|
+
def **(rhs) = self.class.new((@int ** rhs.to_i).to_int)
|
243
|
+
|
244
|
+
# Shifts +self+ left by +rhs+ bits.
|
245
|
+
def <<(rhs) = self.class.new(@int << rhs.to_i)
|
246
|
+
|
247
|
+
# Shifts +self+ right by +rhs+ bits.
|
248
|
+
def >>(rhs) = self.class.new(@int >> rhs.to_i)
|
249
|
+
|
250
|
+
# Bitwise ANDs +self+ and +rhs+.
|
251
|
+
def &(rhs) = self.class.new(@int & rhs.to_i)
|
252
|
+
|
253
|
+
# Bitwise ORs +self+ and +rhs+.
|
254
|
+
def |(rhs) = self.class.new(@int | rhs.to_i)
|
255
|
+
|
256
|
+
# Bitwise XORs +self+ and +rhs+.
|
257
|
+
def ^(rhs) = self.class.new(@int ^ rhs.to_i)
|
258
|
+
|
257
259
|
# Gets the bit at index +idx+ or returns +nil+.
|
258
260
|
#
|
259
261
|
# This is equivalent to +Integer#[]+
|
@@ -267,39 +269,34 @@ class BitInt < Numeric
|
|
267
269
|
def size = (self.class::BITS / 8.0).ceil
|
268
270
|
|
269
271
|
|
270
|
-
PACK_FMT = {
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
}.freeze
|
281
|
-
private_constant :PACK_FMT
|
282
|
-
|
283
|
-
def bytes(endian = :native)
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
end
|
300
|
-
end
|
301
|
-
|
302
|
-
|
303
|
-
(-128..127).each do |n|
|
304
|
-
puts (BitInt::I(8).new(n)).to_s(2)
|
272
|
+
# PACK_FMT = {
|
273
|
+
# [:native, 8, false].freeze => 'C',
|
274
|
+
# [:native, 16, false].freeze => 'S',
|
275
|
+
# [:native, 32, false].freeze => 'L',
|
276
|
+
# [:native, 64, false].freeze => 'Q',
|
277
|
+
# [:native, 8, true].freeze => 'c',
|
278
|
+
# [:native, 16, true].freeze => 's',
|
279
|
+
# [:native, 32, true].freeze => 'l',
|
280
|
+
# [:native, 64, true].freeze => 'q',
|
281
|
+
|
282
|
+
# }.freeze
|
283
|
+
# private_constant :PACK_FMT
|
284
|
+
|
285
|
+
# def bytes(endian = :native)
|
286
|
+
# size = {
|
287
|
+
# 8 => 'C',
|
288
|
+
# 16 => 'S',
|
289
|
+
# 32 => 'L',
|
290
|
+
# 64 => 'Q'
|
291
|
+
# }[self.class::BITS] or raise ArgumentError, "bytes only works for 8, 16, 32, or 64 rn." or raise ArgumentError, "endian must be :big, :little, or :native"
|
292
|
+
# size = {8=>'C', 16=>}
|
293
|
+
# size = case self.class::BITS
|
294
|
+
# when 8 then 'C'
|
295
|
+
# when 8 then 'C'
|
296
|
+
# # sprintf "%0#{self.class::BYTES * 2}x",
|
297
|
+
# # mask = self.class::MASK_CHAR or raise ArgumentError, "bytes only works (rn) on "
|
298
|
+
# # pack_char = self.class.pack_Char
|
299
|
+
# # case endian
|
300
|
+
# # when :native then
|
301
|
+
# end
|
305
302
|
end
|
data/lib/bitint/version.rb
CHANGED