(149 lines)
4 In the binary representation of a byte, check whether a given bit index is5 set to 1 or not.7 The bit index must be between 1-8 or a runtime error will be produced.11 Whether or not the given bit index is set to 1 in the byte.16 The byte whose bits are being inspected.20 The index of the bit to check (1-indexed, range 1-8).22 assert Byte(6).get_bit(1) == no23 assert Byte(6).get_bit(2) == yes24 assert Byte(6).get_bit(3) == yes25 assert Byte(6).get_bit(4) == no30 Convert a byte to a hexidecimal text representation.34 The byte as a hexidecimal text.39 The byte to convert to hex.44 Whether or not to use uppercase hexidecimal letters.49 Whether or not to prepend a `0x` prefix.51 assert Byte(18).hex(prefix=yes) == "0x12"56 Determines if an integer is between two numbers (inclusive).60 `yes` if `a <= x and x <= b` or `b <= x and x <= a`, otherwise `no`65 The integer to be checked.69 One end of the range to check (inclusive);73 The other end of the range to check (inclusive);75 assert Byte(7).is_between(1, 10) == yes76 assert Byte(7).is_between(10, 1) == yes77 assert Byte(7).is_between(100, 200) == no78 assert Byte(7).is_between(1, 7) == yes83 Parse a byte literal from text.87 The byte parsed from the text, if successful, otherwise `none`.92 The text to parse.97 The numeric base to use when parsing the byte. If unspecified, the98 byte's base will be inferred from the text prefix. After any "+" or "-"99 sign, if the text begins with "0x", the base will be assumed to be 16,100 "0o" will assume base 8, "0b" will assume base 2, otherwise the base101 will be assumed to be 10.106 If non-none, this argument will be set to the remainder of the text after the matching part.107 If none, parsing will only succeed if the entire text matches.109 assert Byte.parse("5") == Byte(5)110 assert Byte.parse("asdf") == none111 assert Byte.parse("123xyz") == none113 remainder : Text114 assert Byte.parse("123xyz", remainder=&remainder) == Byte(123)115 assert remainder == "xyz"120 Returns an iterator function that iterates over the range of bytes specified.124 An iterator function that returns each byte in the given range (inclusive).129 The starting value of the range.133 The ending value of the range.138 An optional step size to use. If unspecified or `none`, the step will be inferred to be `+1` if `last >= first`, otherwise `-1`.140 iter := Byte(2).to(4)141 assert iter() == Byte(2)142 assert iter() == Byte(3)143 assert iter() == Byte(4)144 assert iter() == none146 assert [x for x in Byte(2).to(5)] == [Byte(2), Byte(3), Byte(4), Byte(5)]147 assert [x for x in Byte(5).to(2)] == [Byte(5), Byte(4), Byte(3), Byte(2)]148 assert [x for x in Byte(2).to(5, step=2)] == [Byte(2), Byte(4)]