Added twc_uint32_reverse_bytes function.

This commit is contained in:
Håvard Pettersson 2014-10-04 23:50:44 +02:00
parent 069c4540ec
commit 1d64f5ac50
2 changed files with 18 additions and 0 deletions

View File

@ -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;
}

View File

@ -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