aboutsummaryrefslogtreecommitdiff
path: root/endian.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xendian.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/endian.c b/endian.c
index ea326a9..3f380e3 100755
--- a/endian.c
+++ b/endian.c
@@ -10,8 +10,8 @@
u16 be16(u16 x)
{
- return (x>>8) |
- (x<<8);
+ return (u16)(((x>>8)) |
+ ((x&0xff)<<8));
}
u32 be32(u32 x)
@@ -22,6 +22,29 @@ u32 be32(u32 x)
(x<<24);
}
+u32 int_swap_bytes(u32 int1)
+{
+ unsigned char *int1c; int1c = (unsigned char*)&int1;
+
+ unsigned char charTemp = 0x00;
+ charTemp = int1c[0]; int1c[0] = int1c[3]; int1c[3] = charTemp;
+ charTemp = 0x00;
+ charTemp = int1c[1]; int1c[1] = int1c[2]; int1c[2] = charTemp;
+
+ u32 *newInt; newInt = (int*)int1c;
+ return *newInt;
+}
+
+u16 short_swap_bytes(u16 short1)
+{
+ unsigned char* short1c; short1c = (unsigned char*)&short1;
+ unsigned char charTemp = 0x00;
+ charTemp = short1c[0]; short1c[0] = short1c[1]; short1c[1] = charTemp;
+
+ unsigned short *newShort; newShort = (unsigned short*)short1c;
+ return *newShort;
+}
+
// __int64 for MSVC, "long long" for gcc
u64 be64(u64 x)
{