tango.core.ByteSwap

License:

BSD style: see license.txt

Version:

Initial release: October 2004

Version:

Feb 20th 2005 - Asm version removed by Aleksey Bobnev

Authors:

Kris, Aleksey Bobnev
struct ByteSwap
Reverse byte order for specific datum sizes. Note that the byte-swap approach avoids alignment issues, so is probably faster overall than a traditional 'shift' implementation.
1
2
3
4
5
6
7
8
9
10
11
12
13
ubyte[] x = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08];

auto a = x.dup;
ByteSwap.swap16(a);
assert(a == [cast(ubyte) 0x02, 0x01, 0x04, 0x03, 0x06, 0x05, 0x08, 0x07]);

auto b = x.dup;
ByteSwap.swap32(b);
assert(b == [cast(ubyte) 0x04, 0x03, 0x02, 0x01, 0x08, 0x07, 0x06, 0x05]);

auto c = x.dup;
ByteSwap.swap64(c);
assert(c == [cast(ubyte) 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01]);
void swap16(void[] dst) [static, final]
Reverses two-byte sequences. Parameter dst imples the number of bytes, which should be a multiple of 2
void swap32(void[] dst) [static, final]
Reverses four-byte sequences. Parameter dst implies the number of bytes, which should be a multiple of 4
void swap64(void[] dst) [static, final]
Reverse eight-byte sequences. Parameter dst implies the number of bytes, which should be a multiple of 8
void swap80(void[] dst) [static, final]
Reverse ten-byte sequences. Parameter dst implies the number of bytes, which should be a multiple of 10
void swap16(void* dst, size_t bytes) [static, final]
Reverses two-byte sequences. Parameter bytes specifies the number of bytes, which should be a multiple of 2
void swap32(void* dst, size_t bytes) [static, final]
Reverses four-byte sequences. Parameter bytes specifies the number of bytes, which should be a multiple of 4
void swap64(void* dst, size_t bytes) [static, final]
Reverse eight-byte sequences. Parameter bytes specifies the number of bytes, which should be a multiple of 8
void swap80(void* dst, size_t bytes) [static, final]
Reverse ten-byte sequences. Parameter bytes specifies the number of bytes, which should be a multiple of 10