Module: BitCounter

Extended by:
CImpl, JavaImpl
Defined in:
lib/bit_counter.rb,
lib/bit_counter/cruby.rb,
lib/bit_counter/jruby.rb,
lib/bit_counter/version.rb,
ext/bit_counter/bit_counter.c

Overview

module for bit counting

Defined Under Namespace

Modules: CImpl, JavaImpl

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Methods included from CImpl

count_bignum, count_fixnum, cpu_popcnt?

Methods included from JavaImpl

count_bignum, count_fixnum

Class Method Details

.count(num) ⇒ Integer

counts bits in Integer.

Returns:

  • (Integer)

    num the number of bits. if positive number is given, count 1 bits. if negative number is given, count 0 bits and -(count) is returned.

Raises:

  • (TypeError)

    when non-Integer was given.


24
25
26
27
28
29
30
31
32
33
# File 'lib/bit_counter.rb', line 24

def count(num)
  case num
  when Fixnum
    count_fixnum(num)
  when Bignum
    count_bignum(num)
  else
    raise TypeError
  end
end