2021-06-29 | Paul Boddie | file changeset files shortlog | Renamed the utf8string class to unicode, eliminating the unicode function. This means that the simple case of merely returning an object if it is already a Unicode object no longer occurs when using the unicode callable, but such behaviour might be better supported with more general customised instantiation functionality. |
paul@798 | 1 | def encode(value): |
paul@798 | 2 | return ((value & 8) << 4) | ((value & 4) << 3) | ((value & 2) << 2) | ((value & 1) << 1) |
paul@798 | 3 | |
paul@798 | 4 | print encode(15) # 170 |
paul@798 | 5 | print encode(8) # 128 |
paul@798 | 6 | print encode(2) # 8 |
paul@798 | 7 | print encode(0) # 0 |