Class: BinaryParser::BuiltInTemplate::UInt
- Inherits:
-
TemplateBase
show all
- Includes:
- Comparable
- Defined in:
- lib/binary_parser/built_in_template/uint.rb
Direct Known Subclasses
UIntN
Constant Summary
BCD, BCD_f1, BCD_f10, BCD_f2, BCD_f3, BCD_f4, BCD_f5, BCD_f6, BCD_f7, BCD_f8, BCD_f9
Instance Method Summary
collapse
Def, #binary_bit_length, #convert_into_abstract_binary, def_structure, def_var_method, #hold_enough_binary?, #hold_just_binary?, #initialize, #load, #names, #show, structure, #structure_bit_length, #to_chars, #to_i
bcd_make
Instance Method Details
#*(other) ⇒ Object
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/binary_parser/built_in_template/uint.rb', line 38
def *(other)
if other.is_a?(UInt)
self.to_i * other.to_i
elsif other.is_a?(Integer)
self.to_i * other
else
x, y = other.coerce(self)
x * y
end
end
|
#+(other) ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/binary_parser/built_in_template/uint.rb', line 27
def +(other)
if other.is_a?(UInt)
self.to_i + other.to_i
elsif other.is_a?(Integer)
self.to_i + other
else
x, y = other.coerce(self)
x + y
end
end
|
#-(other) ⇒ Object
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/binary_parser/built_in_template/uint.rb', line 49
def -(other)
if other.is_a?(UInt)
self.to_i - other.to_i
elsif other.is_a?(Integer)
self.to_i - other
else
x, y = other.coerce(self)
x - y
end
end
|
#/(other) ⇒ Object
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/binary_parser/built_in_template/uint.rb', line 60
def /(other)
if other.is_a?(UInt)
self.to_i / other.to_i
elsif other.is_a?(Integer)
self.to_i / other
else
x, y = other.coerce(self)
x / y
end
end
|
#<=>(other) ⇒ Object
71
72
73
74
75
76
77
78
79
|
# File 'lib/binary_parser/built_in_template/uint.rb', line 71
def <=>(other)
if other.is_a?(UInt)
self.to_i <=> other.to_i
elsif other.is_a?(Integer)
self.to_i <=> other
else
nil
end
end
|
#[](bit_index) ⇒ Object
15
16
17
|
# File 'lib/binary_parser/built_in_template/uint.rb', line 15
def [](bit_index)
self.to_i[bit_index]
end
|
#coerce(other) ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/binary_parser/built_in_template/uint.rb', line 19
def coerce(other)
if other.is_a?(Integer)
return other, self.to_i
else
super
end
end
|
#content_description ⇒ Object
7
8
9
|
# File 'lib/binary_parser/built_in_template/uint.rb', line 7
def content_description
"#{self.to_i.to_s} (0x#{self.to_i.to_s(16)})"
end
|
#to_s(base = 10) ⇒ Object
11
12
13
|
# File 'lib/binary_parser/built_in_template/uint.rb', line 11
def to_s(base=10)
self.to_i.to_s(base)
end
|