1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
Byte.get_bit:
short: check whether a bit is set
description: >
In the binary representation of a byte, check whether a given bit index is
set to 1 or not.
note: >
The bit index must be between 1-8 or a runtime error will be produced.
return:
type: 'Bool'
description: >
Whether or not the given bit index is set to 1 in the byte.
args:
i:
type: 'Byte'
description: >
The byte whose bits are being inspected.
bit_index:
type: 'Int'
description: >
The index of the bit to check (1-indexed, range 1-8).
example: |
>> Byte(6).get_bit(1)
= no
>> Byte(6).get_bit(2)
= yes
>> Byte(6).get_bit(3)
= yes
>> Byte(6).get_bit(4)
= no
Byte.hex:
short: convert to hexidecimal
description: >
Convert a byte to a hexidecimal text representation.
return:
type: 'Text'
description: >
The byte as a hexidecimal text.
args:
byte:
type: 'Byte'
description: >
The byte to convert to hex.
uppercase:
type: 'Bool'
default: 'yes'
description: >
Whether or not to use uppercase hexidecimal letters.
prefix:
type: 'Bool'
default: 'no'
description: >
Whether or not to prepend a `0x` prefix.
example: |
>> Byte(18).hex()
= "0x12"
Byte.is_between:
short: test if inside a range
description: >
Determines if an integer is between two numbers (inclusive).
return:
type: 'Bool'
description: >
`yes` if `low <= x and x <= high`, otherwise `no`
args:
x:
type: 'Byte'
description: >
The integer to be checked.
low:
type: 'Byte'
description: >
The lower bound to check (inclusive).
high:
type: 'Byte'
description: >
The upper bound to check (inclusive).
example: |
>> Byte(7).is_between(1, 10)
= yes
>> Byte(7).is_between(100, 200)
= no
>> Byte(7).is_between(1, 7)
= yes
Byte.parse:
short: convert text to a byte
description: >
Parse a byte literal from text.
return:
type: 'Byte?'
description: >
The byte parsed from the text, if successful, otherwise `none`.
args:
text:
type: 'Text'
description: >
The text to parse.
example: |
>> Byte.parse("5")
= Byte(5)?
>> Byte.parse("asdf")
= none
Byte.to:
short: iterate over a range of bytes
description: >
Returns an iterator function that iterates over the range of bytes specified.
return:
type: 'func(->Byte?)'
description: >
An iterator function that returns each byte in the given range (inclusive).
args:
first:
type: 'Byte'
description: >
The starting value of the range.
last:
type: 'Byte'
description: >
The ending value of the range.
step:
type: 'Byte?'
default: 'none'
description: >
An optional step size to use. If unspecified or `none`, the step will be inferred to be `+1` if `last >= first`, otherwise `-1`.
example: |
>> Byte(2).to(5)
= func(->Byte?)
>> [x for x in Byte(2).to(5)]
= [Byte(2), Byte(3), Byte(4), Byte(5)]
>> [x for x in Byte(5).to(2)]
= [Byte(5), Byte(4), Byte(3), Byte(2)]
>> [x for x in Byte(2).to(5, step=2)]
= [Byte(2), Byte(4)]
|