class Integer

Attributes

width[RW]

Public Instance Methods

bit_mask()
Alias for: to_bit_mask
cycle()
Alias for: cycles
cycles() { || ... } click to toggle source

Implements 10.cycles

# File lib/origen/core_ext/integer.rb, line 35
def cycles
  if block_given?
    times do
      yield
      Origen.app.tester.cycle
    end
  else
    Origen.app.tester.cycle(repeat: self)
  end
end
Also aliased as: cycle
ones_comp(num_bits) click to toggle source
# File lib/origen/core_ext/integer.rb, line 47
def ones_comp(num_bits)
  self ^ ((1 << num_bits) - 1)
end
Also aliased as: ones_complement, ones_compliment
ones_complement(num_bits)
Alias for: ones_comp
ones_compliment(num_bits)
Alias for: ones_comp
to_bit_mask() click to toggle source

Returns a bit mask for the given number of bits:

4.to_bit_mask  # => 0x1111
# File lib/origen/core_ext/integer.rb, line 56
def to_bit_mask
  (1 << self) - 1
end
Also aliased as: bit_mask
to_bool() click to toggle source
# File lib/origen/core_ext/integer.rb, line 61
def to_bool
  if self == 1
    true
  elsif self == 0
    false
  end
end
to_spreadsheet_col()
to_spreadsheet_column() click to toggle source
# File lib/origen/core_ext/integer.rb, line 69
def to_spreadsheet_column
  index_hash = Hash.new { |hash, key| hash[key] = hash[key - 1].next }.merge(0 => 'A')
  index_hash[self]
end
to_xls_col()
to_xls_column()
to_xlsx_col()
to_xlsx_column()
twos_comp(width = nil)
Alias for: twos_complement
twos_complement(width = nil) click to toggle source
# File lib/origen/core_ext/integer.rb, line 79
def twos_complement(width = nil)
  _width = width || Integer.width
  if self > 2**(_width - 1) - 1
    fail(RangeError, "Integer #{self} cannot fit into #{_width} bits with 2s complement encoding")
  elsif self < -1 * (2**(_width - 1))
    fail(RangeError, "Integer #{self} cannot fit into #{_width} bits with 2s complement encoding")
  end

  self < 0 ? ((-1 * self) ^ (2**_width - 1)) + 1 : self
end
Also aliased as: twos_comp, twos_compliment
twos_compliment(width = nil)
Alias for: twos_complement