Version 2.1.0.0

ProperBitConverter class

Namespace: Sirenix.Serialization
Assembly: Sirenix.Serialization
public static class ProperBitConverter
Corresponds to the .NET System.BitConverter class, but works only with buffers and so never allocates garbage.

This class always writes and reads bytes in a little endian format, regardless of system architecture.

Inheritance
  • System.Object
  • ProperBitConverter

Methods

BytesToHexString(Byte[], Boolean)
Converts a byte array into a hexadecimal string.
public static string BytesToHexString(byte[] bytes, bool lowerCaseHexChars = true)
Parameters
System.Byte[] bytes

System.Boolean lowerCaseHexChars

Returns
System.String

GetBytes(Byte[], Int32, Decimal)
Turns a System.Decimal value into sixteen bytes and writes those bytes to a given buffer.
public static void GetBytes(byte[] buffer, int index, decimal value)
Parameters
System.Byte[] buffer

The buffer to write to.

System.Int32 index

The index to start writing at.

System.Decimal value

The value to write.

GetBytes(Byte[], Int32, Double)
Turns a System.Double value into eight bytes and writes those bytes to a given buffer.
public static void GetBytes(byte[] buffer, int index, double value)
Parameters
System.Byte[] buffer

The buffer to write to.

System.Int32 index

The index to start writing at.

System.Double value

The value to write.

GetBytes(Byte[], Int32, Guid)
Turns a System.Guid value into sixteen bytes and writes those bytes to a given buffer.
public static void GetBytes(byte[] buffer, int index, Guid value)
Parameters
System.Byte[] buffer

The buffer to write to.

System.Int32 index

The index to start writing at.

System.Guid value

The value to write.

GetBytes(Byte[], Int32, Int16)
Turns a System.Int16 value into two bytes and writes those bytes to a given buffer.
public static void GetBytes(byte[] buffer, int index, short value)
Parameters
System.Byte[] buffer

The buffer to write to.

System.Int32 index

The index to start writing at.

System.Int16 value

The value to write.

GetBytes(Byte[], Int32, Int32)
Turns an System.Int32 value into four bytes and writes those bytes to a given buffer.
public static void GetBytes(byte[] buffer, int index, int value)
Parameters
System.Byte[] buffer

The buffer to write to.

System.Int32 index

The index to start writing at.

System.Int32 value

The value to write.

GetBytes(Byte[], Int32, Int64)
Turns a System.Int64 value into eight bytes and writes those bytes to a given buffer.
public static void GetBytes(byte[] buffer, int index, long value)
Parameters
System.Byte[] buffer

The buffer to write to.

System.Int32 index

The index to start writing at.

System.Int64 value

The value to write.

GetBytes(Byte[], Int32, Single)
Turns a System.Single value into four bytes and writes those bytes to a given buffer.
public static void GetBytes(byte[] buffer, int index, float value)
Parameters
System.Byte[] buffer

The buffer to write to.

System.Int32 index

The index to start writing at.

System.Single value

The value to write.

GetBytes(Byte[], Int32, UInt16)
Turns an System.UInt16 value into two bytes and writes those bytes to a given buffer.
public static void GetBytes(byte[] buffer, int index, ushort value)
Parameters
System.Byte[] buffer

The buffer to write to.

System.Int32 index

The index to start writing at.

System.UInt16 value

The value to write.

GetBytes(Byte[], Int32, UInt32)
Turns an System.UInt32 value into four bytes and writes those bytes to a given buffer.
public static void GetBytes(byte[] buffer, int index, uint value)
Parameters
System.Byte[] buffer

The buffer to write to.

System.Int32 index

The index to start writing at.

System.UInt32 value

The value to write.

GetBytes(Byte[], Int32, UInt64)
Turns an System.UInt64 value into eight bytes and writes those bytes to a given buffer.
public static void GetBytes(byte[] buffer, int index, ulong value)
Parameters
System.Byte[] buffer

The buffer to write to.

System.Int32 index

The index to start writing at.

System.UInt64 value

The value to write.

HexStringToBytes(String)
Converts a hexadecimal string into a byte array.
public static byte[] HexStringToBytes(string hex)
Parameters
System.String hex

Returns
System.Byte[]

ToDecimal(Byte[], Int32)
Reads sixteen bytes from a buffer and converts them into a System.Decimal value.
public static decimal ToDecimal(byte[] buffer, int index)
Parameters
System.Byte[] buffer

The buffer to read from.

System.Int32 index

The index to start reading at.

Returns
System.Decimal

The converted value.

ToDouble(Byte[], Int32)
Reads eight bytes from a buffer and converts them into an System.Double value.
public static double ToDouble(byte[] buffer, int index)
Parameters
System.Byte[] buffer

The buffer to read from.

System.Int32 index

The index to start reading at.

Returns
System.Double

The converted value.

ToGuid(Byte[], Int32)
Reads sixteen bytes from a buffer and converts them into a System.Guid value.
public static Guid ToGuid(byte[] buffer, int index)
Parameters
System.Byte[] buffer

The buffer to read from.

System.Int32 index

The index to start reading at.

Returns
System.Guid

The converted value.

ToInt16(Byte[], Int32)
Reads two bytes from a buffer and converts them into a System.Int16 value.
public static short ToInt16(byte[] buffer, int index)
Parameters
System.Byte[] buffer

The buffer to read from.

System.Int32 index

The index to start reading at.

Returns
System.Int16

The converted value.

ToInt32(Byte[], Int32)
Reads four bytes from a buffer and converts them into an System.Int32 value.
public static int ToInt32(byte[] buffer, int index)
Parameters
System.Byte[] buffer

The buffer to read from.

System.Int32 index

The index to start reading at.

Returns
System.Int32

The converted value.

ToInt64(Byte[], Int32)
Reads eight bytes from a buffer and converts them into a System.Int64 value.
public static long ToInt64(byte[] buffer, int index)
Parameters
System.Byte[] buffer

The buffer to read from.

System.Int32 index

The index to start reading at.

Returns
System.Int64

The converted value.

ToSingle(Byte[], Int32)
Reads four bytes from a buffer and converts them into an System.Single value.
public static float ToSingle(byte[] buffer, int index)
Parameters
System.Byte[] buffer

The buffer to read from.

System.Int32 index

The index to start reading at.

Returns
System.Single

The converted value.

ToUInt16(Byte[], Int32)
Reads two bytes from a buffer and converts them into a System.UInt16 value.
public static ushort ToUInt16(byte[] buffer, int index)
Parameters
System.Byte[] buffer

The buffer to read from.

System.Int32 index

The index to start reading at.

Returns
System.UInt16

The converted value.

ToUInt32(Byte[], Int32)
Reads four bytes from a buffer and converts them into an System.UInt32 value.
public static uint ToUInt32(byte[] buffer, int index)
Parameters
System.Byte[] buffer

The buffer to read from.

System.Int32 index

The index to start reading at.

Returns
System.UInt32

The converted value.

ToUInt64(Byte[], Int32)
Reads eight bytes from a buffer and converts them into an System.UInt64 value.
public static ulong ToUInt64(byte[] buffer, int index)
Parameters
System.Byte[] buffer

The buffer to read from.

System.Int32 index

The index to start reading at.

Returns
System.UInt64

The converted value.

This website is brand new and built with the Odin 2.1 beta in mind. This means you might discover some features such as attribute expressions that are only available in the beta.

You can download the 2.1 beta from here and read the patch-notes here.