diff --git a/src/twc-utils.c b/src/twc-utils.c index 1c4c1bd..75e0b6f 100644 --- a/src/twc-utils.c +++ b/src/twc-utils.c @@ -148,3 +148,18 @@ twc_get_friend_id_short(Tox *tox, int32_t friend_number) return hex_address; } +/** + * Reverse the bytes of a 32-bit integer. + */ +uint32_t +twc_uint32_reverse_bytes(uint32_t num) +{ + uint32_t res = 0; + + res += num & 0xFF; num >>= 8; res <<= 8; + res += num & 0xFF; num >>= 8; res <<= 8; + res += num & 0xFF; num >>= 8; res <<= 8; + res += num & 0xFF; + + return res; +} diff --git a/src/twc-utils.h b/src/twc-utils.h index 1c3ab90..5d482b2 100644 --- a/src/twc-utils.h +++ b/src/twc-utils.h @@ -48,5 +48,8 @@ twc_get_self_name_nt(Tox *tox); char * twc_get_friend_id_short(Tox *tox, int32_t friend_number); +uint32_t +twc_uint32_reverse_bytes(uint32_t num); + #endif // TOX_WEECHAT_UTILS_H