/*
Type Can Safely Be Converted To
Byte short, ushort, int, uint, long, ulong, float, double, decimal
Sbyte short, int, long, float, double, decimal
Short int, long, float, double, decimal
Ushort int, uint, long, ulong, float, double, decimal
Int long, float, double, decimal
Uint long, ulong, float, double, decimal
Long float, double, decimal
Ulong float, double, decimal
Float double
Char ushort, int, uint, long, ulong, float, double, decimal
*/
Month: February 2011
Byte array Index Of
//GNU General Public License version 2 (GPLv2)
//http://walkmen.codeplex.com/license
using System;
using System.Collections.Generic;
using System.Text;
namespace Walkmen.Util
{
public sealed class ByteUtils
{
private ByteUtils()
{
}
public static int IndexOf(byte[] array, byte[] pattern, int offset)
{
int success = 0;
for (int i = offset; i < array.Length; i++)
{
if (array[i] == pattern[success])
{
success++;
}
else
{
success = 0;
}
if (pattern.Length == success)
{
return i - pattern.Length + 1;
}
}
return -1;
}
}
}
[/csharp]
Write int 32 to byte array
//http://walkmen.codeplex.com/license
// License: GNU General Public License version 2 (GPLv2)
using System;
using System.Collections.Generic;
using System.Text;
namespace Walkmen.Util
{
public sealed class NumericUtils
{
private NumericUtils()
{
}
public static byte[] WriteInt32(int value)
{
byte[] result = new byte[4];
result[0] = (byte)((value & 0xFF000000) >> 24);
result[1] = (byte)((value & 0x00FF0000) >> 16);
result[2] = (byte)((value & 0x0000FF00) >> 8);
result[3] = (byte)((value & 0x000000FF));
return result;
}
}
}
Read int 32 from byte array
//http://walkmen.codeplex.com/license
// License: GNU General Public License version 2 (GPLv2)
using System;
using System.Collections.Generic;
using System.Text;
namespace Walkmen.Util
{
public sealed class NumericUtils
{
private NumericUtils()
{
}
public static int ReadInt32(byte[] buffer, int offset)
{
return (buffer[offset + 0] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + (buffer[offset + 3]);
}
}
}
[/csharp]
Read Int 24 from byte array
//http://walkmen.codeplex.com/license
// License: GNU General Public License version 2 (GPLv2)
using System;
using System.Collections.Generic;
using System.Text;
namespace Walkmen.Util
{
public sealed class NumericUtils
{
private NumericUtils()
{
}
public static int ReadInt24(byte[] buffer, int offset)
{
return (buffer[offset + 0] << 16) + (buffer[offset + 1] << 8) + (buffer[offset + 2]);
}
}
}
[/csharp]
Write short value to byte array
//http://walkmen.codeplex.com/license
// License: GNU General Public License version 2 (GPLv2)
using System;
using System.Collections.Generic;
using System.Text;
namespace Walkmen.Util
{
public sealed class NumericUtils
{
private NumericUtils()
{
}
public static byte[] WriteShort(short value)
{
byte[] result = new byte[2];
result[0] = (byte)((value & 0xFF00) >> 8);
result[1] = (byte)((value & 0x00FF));
return result;
}
}
}
Read short from byte array
//http://walkmen.codeplex.com/license
// License: GNU General Public License version 2 (GPLv2)
using System;
using System.Collections.Generic;
using System.Text;
namespace Walkmen.Util
{
public sealed class NumericUtils
{
private NumericUtils()
{
}
public static short ReadShort(byte[] buffer, int offset)
{
return (short)((buffer[offset + 0] << 8) + buffer[offset + 1]);
}
}
}
[/csharp]

