You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
trezor-firmware/core/embed/rust/src/protobuf/zigzag.rs

10 lines
252 B

// 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))
}