1 // Copyright 2001-2019 Crytek GmbH / Crytek Group. All rights reserved.
3 namespace MiscUtil
.Conversion
6 /// Implementation of EndianBitConverter which converts to/from big-endian
9 public sealed class BigEndianBitConverter
: EndianBitConverter
12 /// Indicates the byte order ("endianess") in which data is converted using this class.
15 /// Different computer architectures store data using different byte orders. "Big-endian"
16 /// means the most significant byte is on the left end of a word. "Little-endian" means the
17 /// most significant byte is on the right end of a word.
19 /// <returns>true if this converter is little-endian, false otherwise.</returns>
20 public sealed override bool IsLittleEndian()
26 /// Indicates the byte order ("endianess") in which data is converted using this class.
28 public sealed override Endianness Endianness
30 get { return Endianness.BigEndian; }
34 /// Copies the specified number of bytes from value to buffer, starting at index.
36 /// <param name="value">The value to copy</param>
37 /// <param name="bytes">The number of bytes to copy</param>
38 /// <param name="buffer">The buffer to copy the bytes into</param>
39 /// <param name="index">The index to start at</param>
40 protected override void CopyBytesImpl(long value, int bytes
, byte[] buffer
, int index
)
42 int endOffset
= index
+bytes
-1;
43 for (int i
=0; i
< bytes
; i
++)
45 buffer
[endOffset
-i
] = unchecked((byte)(value&0xff));
51 /// Returns a value built from the specified number of bytes from the given buffer,
52 /// starting at index.
54 /// <param name="buffer">The data in byte array format</param>
55 /// <param name="startIndex">The first index to use</param>
56 /// <param name="bytesToConvert">The number of bytes to use</param>
57 /// <returns>The value built from the given bytes</returns>
58 protected override long FromBytes(byte[] buffer
, int startIndex
, int bytesToConvert
)
61 for (int i
=0; i
< bytesToConvert
; i
++)
63 ret
= unchecked((ret
<< 8) | buffer
[startIndex
+i
]);