From 1d64f5ac509ca2f4fffd413c27049c8572dd93fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Pettersson?= Date: Sat, 4 Oct 2014 23:50:44 +0200 Subject: [PATCH] Added twc_uint32_reverse_bytes function. --- src/twc-utils.c | 15 +++++++++++++++ src/twc-utils.h | 3 +++ 2 files changed, 18 insertions(+) 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