Created
June 10, 2014 08:09
-
-
Save huoxudong125/992b770f5d7a978c722a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! Byte swap unsigned short | |
static uint16_t swap_uint16(uint16_t val) | |
{ | |
return (val << 8) | (val >> 8); | |
} | |
//! Byte swap short | |
static int16_t swap_int16(int16_t val) | |
{ | |
return (val << 8) | ((val >> 8) & 0xFF); | |
} | |
//! Byte swap unsigned int | |
static uint32_t swap_uint32(uint32_t val) | |
{ | |
val = ((val << 8) & 0xFF00FF00) | ((val >> 8) & 0xFF00FF); | |
return (val << 16) | (val >> 16); | |
} | |
//! Byte swap int | |
static int32_t swap_int32(int32_t val) | |
{ | |
val = ((val << 8) & 0xFF00FF00) | ((val >> 8) & 0xFF00FF); | |
return (val << 16) | ((val >> 16) & 0xFFFF); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment