mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-01-11 19:44:55 +00:00
refactor[BigEndianBitConverter]: Reduce code reuse in GetBytes methods
This commit is contained in:
@@ -101,17 +101,7 @@ namespace ICD.Common.Utils
|
|||||||
}
|
}
|
||||||
public static byte[] GetBytes(uint value)
|
public static byte[] GetBytes(uint value)
|
||||||
{
|
{
|
||||||
if (!BitConverter.IsLittleEndian)
|
return unchecked(GetBytes((int)value));
|
||||||
return BitConverter.GetBytes(value);
|
|
||||||
|
|
||||||
const int total_bytes = sizeof(uint);
|
|
||||||
|
|
||||||
byte[] response = new byte[total_bytes];
|
|
||||||
|
|
||||||
for (int i = 0; i < total_bytes; i++)
|
|
||||||
response[i] = (byte)(value >> GetBitShift(i,total_bytes) & FULL_BYTE);
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] GetBytes(short value)
|
public static byte[] GetBytes(short value)
|
||||||
@@ -131,17 +121,7 @@ namespace ICD.Common.Utils
|
|||||||
|
|
||||||
public static byte[] GetBytes(ushort value)
|
public static byte[] GetBytes(ushort value)
|
||||||
{
|
{
|
||||||
if (!BitConverter.IsLittleEndian)
|
return unchecked(GetBytes((short)value));
|
||||||
return BitConverter.GetBytes(value);
|
|
||||||
|
|
||||||
const int total_bytes = sizeof(short);
|
|
||||||
|
|
||||||
byte[] response = new byte[total_bytes];
|
|
||||||
|
|
||||||
for (int i = 0; i < total_bytes; i++)
|
|
||||||
response[i] = (byte)(value >> GetBitShift(i,total_bytes) & FULL_BYTE);
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] GetBytes(long value)
|
public static byte[] GetBytes(long value)
|
||||||
@@ -161,17 +141,7 @@ namespace ICD.Common.Utils
|
|||||||
|
|
||||||
public static byte[] GetBytes(ulong value)
|
public static byte[] GetBytes(ulong value)
|
||||||
{
|
{
|
||||||
if (!BitConverter.IsLittleEndian)
|
return unchecked(GetBytes((long)value));
|
||||||
return BitConverter.GetBytes(value);
|
|
||||||
|
|
||||||
const int total_bytes = sizeof(ulong);
|
|
||||||
|
|
||||||
byte[] response = new byte[total_bytes];
|
|
||||||
|
|
||||||
for (int i = 0; i < total_bytes; i++)
|
|
||||||
response[i] = (byte)(value >> GetBitShift(i,total_bytes) & FULL_BYTE);
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
private static int GetBitShift(int byteNumber, int totalBytes)
|
private static int GetBitShift(int byteNumber, int totalBytes)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user