exectos/xtoskrnl/rtl/byteswap.c
belliash d8c68ed003
All checks were successful
ci/woodpecker/push/build Pipeline was successful
Add endian conversion routines
2023-02-08 16:33:57 +01:00

73 lines
1.7 KiB
C

/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/rtl/byteswap.c
* DESCRIPTION: Endian conversion routines
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/
#include <xtos.h>
/**
* This routine converts endianness on 32bit value.
*
* @param Source
* Supplies a value to swap bytes.
*
* @return Swapped 32bit value.
*
* @since NT 4.0
*/
XTFASTCALL
ULONG
RtlUlongByteSwap(IN ULONG Source)
{
return (ULONG)(((Source >> 24) & 0x000000FF) |
((Source >> 8) & 0x0000FF00) |
((Source << 8) & 0x00FF0000) |
((Source << 24) & 0xFF000000));
}
/**
* This routine converts endianness on 64bit value.
*
* @param Source
* Supplies a value to swap bytes.
*
* @return Swapped 64bit value.
*
* @since NT 4.0
*/
XTFASTCALL
ULONGLONG
RtlUlonglongByteSwap(IN ULONGLONG Source)
{
return (ULONGLONG)(((Source >> 56) & 0x00000000000000FF) |
((Source >> 40) & 0x000000000000FF00) |
((Source >> 24) & 0x0000000000FF0000) |
((Source >> 8) & 0x00000000FF000000) |
((Source << 8) & 0x000000FF00000000) |
((Source << 24) & 0x0000FF0000000000) |
((Source << 40) & 0x00FF000000000000) |
((Source << 56) & 0xFF00000000000000));
}
/**
* This routine converts endianness on 16bit value.
*
* @param Source
* Supplies a value to swap bytes.
*
* @return Swapped 16bit value.
*
* @since NT 4.0
*/
XTFASTCALL
USHORT
RtlUshortByteSwap(IN USHORT Source)
{
return (USHORT)(((Source >> 8) & 0x00FF) |
((Source << 8) & 0xFF00));
}