2020-07-16 | Paul Boddie | file changeset files shortlog | Fixed int limit macros by actually using the size of the int type. For wider types such as long, which may be usable on 64-bit platforms in place of int, 1L would need to be used instead of 1 in the calculation. An abstract native integer type might be introduced here and to the native library to allow wider types if appropriate. |
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 |