c#中的基本类型转换

/// <summary>
/// char[]转换为string
/// </summary>
public static string CharsToStr(char[] buff)
{
string tmpStr = new string(buff);
return tmpStr.Remove(tmpStr.IndexOf('\0')).Trim();
}
/// <summary>
/// 将Byte[]数据转换为int
/// </summary>
public static int bytesToInt(byte[] bytes)
{
int addr = bytes[0] & 0xFF;
addr |= ((bytes[1] << 8));
addr |= ((bytes[2] << 16));
addr |= ((bytes[3] << 24));
return addr;
}
/// <summary>
/// 将int数据转换为byte[]
/// </summary>
public static byte[] intToByte(int i)
{
byte[] abyte0 = new byte[4];
abyte0[0] = (byte)(0xff & i);
abyte0[1] = (byte)((0xff00 & i) >> 8);
abyte0[2] = (byte)((0xff0000 & i) >> 16);
abyte0[3] = (byte)((0xff000000 & i) >> 24);
return abyte0;
}
public static string FloatToIntegerString(float value)
{
return Math.Round(value).ToString();
}
/// char[]转换为string
/// </summary>
public static string CharsToStr(char[] buff)
{
string tmpStr = new string(buff);
return tmpStr.Remove(tmpStr.IndexOf('\0')).Trim();
}
/// <summary>
/// 将Byte[]数据转换为int
/// </summary>
public static int bytesToInt(byte[] bytes)
{
int addr = bytes[0] & 0xFF;
addr |= ((bytes[1] << 8));
addr |= ((bytes[2] << 16));
addr |= ((bytes[3] << 24));
return addr;
}
/// <summary>
/// 将int数据转换为byte[]
/// </summary>
public static byte[] intToByte(int i)
{
byte[] abyte0 = new byte[4];
abyte0[0] = (byte)(0xff & i);
abyte0[1] = (byte)((0xff00 & i) >> 8);
abyte0[2] = (byte)((0xff0000 & i) >> 16);
abyte0[3] = (byte)((0xff000000 & i) >> 24);
return abyte0;
}
public static string FloatToIntegerString(float value)
{
return Math.Round(value).ToString();
}