_byteswap_uint64, _byteswap_ulong, _byteswap_ushort
div
TOC
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

_byteswap_uint64, _byteswap_ulong, _byteswap_ushort

Reverse the order of bytes in an integer.

unsigned short _byteswap_ushort (
   unsigned short val
);
unsigned long _byteswap_ulong (
   unsigned long val
);
unsigned __int64 _byteswap_uint64 (
   unsigned __int64 val
);

Parameter

val
The integer to reverse byte order.

Requirements

Routine Required header Compatibility
_byteswap_ushort <stdlib.h> Win 98, Win Me, Win NT, Win 2000, Win XP
_byteswap_ulong <stdlib.h> Win 98, Win Me, Win NT, Win 2000, Win XP
_byteswap_uint64 <stdlib.h> Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.

Libraries

All versions of the C run-time libraries.

Example

// crt_byteswap.c
#include <stdlib.h>

int main()
{
   unsigned __int64 u64 = 0x0102030405060708;
   unsigned long ul = 0x01020304;
   
   printf("byteswap of %I64x = %I64x\n", u64, _byteswap_uint64(u64));
   printf("byteswap of %Ix = %Ix", ul, _byteswap_ulong(ul));
}

Output

byteswap of 102030405060708 = 807060504030201
byteswap of 1020304 = 4030201

See Also

Run-Time Routines by Category | Run-Time Routines and .NET Framework Equivalents

Show:
© 2016 Microsoft