1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-03 05:12:34 +00:00
trezor-firmware/core/embed/rust/src/protobuf/zigzag.rs
2021-06-08 09:55:19 +02:00

10 lines
252 B
Rust

// https://developers.google.com/protocol-buffers/docs/encoding#signed_integers
pub fn to_unsigned(sint: i64) -> u64 {
((sint << 1) ^ (sint >> 63)) as u64
}
pub fn to_signed(uint: u64) -> i64 {
((uint >> 1) as i64) ^ (-((uint & 1) as i64))
}