Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

byteswap.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1997 Microsoft Corporation 00004 00005 Module Name: 00006 00007 byteswap.c 00008 00009 Abstract: 00010 00011 This module defines functions for performing endian conversions. 00012 00013 Author: 00014 00015 Forrest Foltz (forrestf) 10-Dec-1997 00016 00017 Revision History: 00018 00019 00020 --*/ 00021 00022 #include "nt.h" 00023 #include "ntrtlp.h" 00024 00025 00026 USHORT 00027 FASTCALL 00028 RtlUshortByteSwap( 00029 IN USHORT Source 00030 ) 00031 00032 /*++ 00033 00034 Routine Description: 00035 00036 The RtlUshortByteSwap function exchanges bytes 0 and 1 of Source 00037 and returns the resulting USHORT. 00038 00039 Arguments: 00040 00041 Source - 16-bit value to byteswap. 00042 00043 Return Value: 00044 00045 Swapped 16-bit value. 00046 00047 --*/ 00048 { 00049 USHORT swapped; 00050 00051 swapped = ((Source) << (8 * 1)) | 00052 ((Source) >> (8 * 1)); 00053 00054 return swapped; 00055 } 00056 00057 00058 ULONG 00059 FASTCALL 00060 RtlUlongByteSwap( 00061 IN ULONG Source 00062 ) 00063 00064 /*++ 00065 00066 Routine Description: 00067 00068 The RtlUlongByteSwap function exchanges byte pairs 0:3 and 1:2 of 00069 Source and returns the resulting ULONG. 00070 00071 Arguments: 00072 00073 Source - 32-bit value to byteswap. 00074 00075 Return Value: 00076 00077 Swapped 32-bit value. 00078 00079 --*/ 00080 { 00081 ULONG swapped; 00082 00083 swapped = ((Source) << (8 * 3)) | 00084 ((Source & 0x0000FF00) << (8 * 1)) | 00085 ((Source & 0x00FF0000) >> (8 * 1)) | 00086 ((Source) >> (8 * 3)); 00087 00088 return swapped; 00089 } 00090 00091 00092 ULONGLONG 00093 FASTCALL 00094 RtlUlonglongByteSwap( 00095 IN ULONGLONG Source 00096 ) 00097 00098 /*++ 00099 00100 Routine Description: 00101 00102 The RtlUlongByteSwap function exchanges byte pairs 0:7, 1:6, 2:5, and 00103 3:4 of Source and returns the resulting ULONGLONG. 00104 00105 Arguments: 00106 00107 Source - 64-bit value to byteswap. 00108 00109 Return Value: 00110 00111 Swapped 64-bit value. 00112 00113 --*/ 00114 { 00115 ULONGLONG swapped; 00116 00117 swapped = ((Source) << (8 * 7)) | 00118 ((Source & 0x000000000000FF00) << (8 * 5)) | 00119 ((Source & 0x0000000000FF0000) << (8 * 3)) | 00120 ((Source & 0x00000000FF000000) << (8 * 1)) | 00121 ((Source & 0x000000FF00000000) >> (8 * 1)) | 00122 ((Source & 0x0000FF0000000000) >> (8 * 3)) | 00123 ((Source & 0x00FF000000000000) >> (8 * 5)) | 00124 ((Source) >> (8 * 7)); 00125 00126 return swapped; 00127 } 00128 00129

Generated on Sat May 15 19:39:19 2004 for test by doxygen 1.3.7