Class: Integer
- Includes:
- Origen::IntegerExtension
- Defined in:
- lib/origen/core_ext/integer.rb
Instance Method Summary collapse
-
#cycles ⇒ Object
(also: #cycle)
Implements 10.cycles.
- #ones_comp(num_bits) ⇒ Object (also: #ones_complement, #ones_compliment)
-
#to_bit_mask ⇒ Object
(also: #bit_mask)
Returns a bit mask for the given number of bits:.
- #to_bool ⇒ Object
- #to_spreadsheet_column ⇒ Object (also: #to_xls_column, #to_xlsx_column, #to_xls_col, #to_xlsx_col, #to_spreadsheet_col)
Methods included from Origen::IntegerExtension
Instance Method Details
#cycles ⇒ Object Also known as: cycle
Implements 10.cycles
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/origen/core_ext/integer.rb', line 30 def cycles if block_given? times do yield Origen.app.tester.cycle end else Origen.app.tester.cycle(repeat: self) end end |
#ones_comp(num_bits) ⇒ Object Also known as: ones_complement, ones_compliment
42 43 44 |
# File 'lib/origen/core_ext/integer.rb', line 42 def ones_comp(num_bits) self ^ ((1 << num_bits) - 1) end |
#to_bit_mask ⇒ Object Also known as: bit_mask
Returns a bit mask for the given number of bits:
4.to_bit_mask # => 0x1111
51 52 53 |
# File 'lib/origen/core_ext/integer.rb', line 51 def to_bit_mask (1 << self) - 1 end |
#to_bool ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/origen/core_ext/integer.rb', line 56 def to_bool if self == 1 return true elsif self == 0 return false else return nil end end |
#to_spreadsheet_column ⇒ Object Also known as: to_xls_column, to_xlsx_column, to_xls_col, to_xlsx_col, to_spreadsheet_col
66 67 68 69 |
# File 'lib/origen/core_ext/integer.rb', line 66 def to_spreadsheet_column index_hash = Hash.new { |hash, key| hash[key] = hash[key - 1].next }.merge(0 => 'A') index_hash[self] end |