using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Configuration;
using System.Threading;
namespace SiaSun.LMS.Common
{
///
/// 所有进制之间的转换函数库
/// Creator:Richard.liu
///
public static class CCarryConvert
{
static Mutex mutex=new Mutex();
///
/// 十进制转十六进制
///
/// 十进制数
/// 十六进制字符串
public static string DecimalToHex(byte dec)
{
return Convert.ToString(dec, 16);
}
///
/// 十进制转十六进制
///
///
///
public static string DecimalToHex(int dec)
{
return Convert.ToString(dec, 16);
}
///
/// 十进制转八进制
///
/// 十进制数
/// 八进制字符串
public static string DecimalToOct(byte dec)
{
return Convert.ToString(dec, 8);
}
///
/// 二进制转十进制
///
/// 二进制字符串
/// 十进制数
public static Int32 BinToDecimal(string bin)
{
return Convert.ToInt32(bin, 2);
}
///
/// 八进制转十进制
///
/// 八进制字符串
/// 十进制数
public static Int32 OctToDecimal(string Oct)
{
return Convert.ToInt32(Oct , 8);
}
///
/// 十六进制转十进制
///
/// 十六进制字符串
/// 十进制数
public static Int32 HexToDecimal(string hex)
{
return Convert.ToInt32(hex , 16);
}
///
/// 十六进制转字节型十进制
///
/// 十六进制字符串
/// 字节型十进制数
public static byte HexToByte(string hex)
{
return Convert.ToByte(hex, 16);
}
///
/// 在十进制数获得指定bit位的二进制字符:0/1
///
/// 十进制数
/// 比特位
///
public static byte GetBitFromInteger(int Int, int bitno)
{
if ((Int & Convert.ToInt32(Math.Pow(2, Convert.ToDouble(bitno)))) == Convert.ToInt32(Math.Pow(2, Convert.ToDouble(bitno))))
{
return 1;
}
else
{
return 0;
}
}
///
/// byte[0]存放高八位,byte[1]存放低八位
///
///
///
public static byte[] GetByteFromInt16(int _int16)
{
char[] cc = new char[1] { '.' };
string[] sp;
byte[] _bytes = new byte[2];
sp = Convert.ToString(_int16 >> 8).Split(cc);
_bytes[0] =Convert.ToByte( sp[0]);
_bytes[1] =Convert.ToByte( _int16 & 255);
return _bytes;
}
public static UInt16 GetInt16FromBytes(byte[] _bytes)
{
UInt16 _int16;
_int16 =Convert.ToUInt16( _bytes[1] +( _bytes[0]*256));
return _int16;
}
}
}