| 137 | |
| 138 | template <typename IntegerType> |
| 139 | IntegerType zigzagDecode (IntegerType n) |
| 140 | { |
| 141 | auto un = static_cast<typename std::make_unsigned<IntegerType>::type> (n); |
| 142 | auto sn = static_cast<typename std::make_signed<IntegerType>::type> (n); |
| 143 | return static_cast<IntegerType> (static_cast<decltype (sn)> (un >> 1) ^ -(sn & static_cast<decltype (sn)> (1))); |
| 144 | } |
| 145 | |
| 146 | } // namespace choc::integer_encoding |
| 147 |