2017-04-27 04:31:01 +00:00
|
|
|
#ifndef B3_SWAP_UTILS_H
|
|
|
|
#define B3_SWAP_UTILS_H
|
|
|
|
|
|
|
|
inline void b3Swap16(unsigned char *ptr)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
unsigned char val;
|
2017-04-27 04:31:01 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
// Swap 1st and 2nd bytes
|
|
|
|
val = *(ptr);
|
|
|
|
*(ptr) = *(ptr + 1);
|
|
|
|
*(ptr + 1) = val;
|
2017-04-27 04:31:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void b3Swap32(unsigned char *ptr)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
unsigned char val;
|
2017-04-27 04:31:01 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
// Swap 1st and 4th bytes
|
|
|
|
val = *(ptr);
|
|
|
|
*(ptr) = *(ptr + 3);
|
|
|
|
*(ptr + 3) = val;
|
|
|
|
|
|
|
|
//Swap 2nd and 3rd bytes
|
|
|
|
ptr += 1;
|
|
|
|
val = *(ptr);
|
|
|
|
*(ptr) = *(ptr + 1);
|
|
|
|
*(ptr + 1) = val;
|
|
|
|
}
|
2017-04-27 04:31:01 +00:00
|
|
|
|
|
|
|
inline void b3Swap64(unsigned char *ptr)
|
|
|
|
{
|
|
|
|
unsigned char val;
|
|
|
|
|
|
|
|
// Swap 1st and 8th bytes
|
|
|
|
val = *(ptr);
|
|
|
|
*(ptr) = *(ptr + 7);
|
|
|
|
*(ptr + 7) = val;
|
|
|
|
|
|
|
|
// Swap 2nd and 7th bytes
|
|
|
|
ptr += 1;
|
|
|
|
val = *(ptr);
|
|
|
|
*(ptr) = *(ptr + 5);
|
|
|
|
*(ptr + 5) = val;
|
|
|
|
|
|
|
|
// Swap 3rd and 6th bytes
|
|
|
|
ptr += 1;
|
|
|
|
val = *(ptr);
|
|
|
|
*(ptr) = *(ptr + 3);
|
|
|
|
*(ptr + 3) = val;
|
|
|
|
|
|
|
|
// Swap 4th and 5th bytes
|
|
|
|
ptr += 1;
|
|
|
|
val = *(ptr);
|
|
|
|
*(ptr) = *(ptr + 1);
|
|
|
|
*(ptr + 1) = val;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
#endif //B3_SWAP_UTILS_H
|