//16位整形数高低字节互换
#define SWAP16(x) ((x & 0xff00) >> 8) | ((x & 0xff) << 8)
//32位高字高字节在前,低字低字节在后
s32 MODEBUS_32HHTO32LL(s32 In32)
{
u16 InL = SWAP16(In32&0xffff);
u16 InH = SWAP16((In32>>16)&0xffff);
return ((InH<<16)|InL);
}
//低字在前,低字节在前;高字在后,高字节在后
s32 MODEBUS_32LLTO32HH(s32 In32)
{
u16 InL = In32&0xffff;
u16 InH = (In32>>16)&0xffff;
return ((InH<<16)|InL);
}
//32位低字在前,高字在后,低字节在前;高字节在后
s32 MODEBUS_32LHTO32LH(s32 In32)
{
u16 InL = In32&0xffff;
u16 InH = (In32>>16)&0xffff;
return ((InL<<16)|InH);
}
//32位低字在前,高字在后,高字节在前;低字节在后
s32 MODEBUS_32LHTO32HL(s32 In32)
{
u16 InL = SWAP16(In32&0xffff);
u16 InH = SWAP16((In32>>16)&0xffff);
return ((InL<<16)|InH);
}
#define SWAP16(x) ((x & 0xff00) >> 8) | ((x & 0xff) << 8)
//32位高字高字节在前,低字低字节在后
s32 MODEBUS_32HHTO32LL(s32 In32)
{
u16 InL = SWAP16(In32&0xffff);
u16 InH = SWAP16((In32>>16)&0xffff);
return ((InH<<16)|InL);
}
//低字在前,低字节在前;高字在后,高字节在后
s32 MODEBUS_32LLTO32HH(s32 In32)
{
u16 InL = In32&0xffff;
u16 InH = (In32>>16)&0xffff;
return ((InH<<16)|InL);
}
//32位低字在前,高字在后,低字节在前;高字节在后
s32 MODEBUS_32LHTO32LH(s32 In32)
{
u16 InL = In32&0xffff;
u16 InH = (In32>>16)&0xffff;
return ((InL<<16)|InH);
}
//32位低字在前,高字在后,高字节在前;低字节在后
s32 MODEBUS_32LHTO32HL(s32 In32)
{
u16 InL = SWAP16(In32&0xffff);
u16 InH = SWAP16((In32>>16)&0xffff);
return ((InL<<16)|InH);
}