2019-02-04 | Paul Boddie | file changeset files shortlog | Optimised __BOOL to test for integers and to return int values directly. For other value types, __VALUE need not be called once integers have been excluded, and so the attrvalue member can be accessed directly. |
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 |