You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
130 lines
3.6 KiB
130 lines
3.6 KiB
1 month ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Text;
|
||
|
using System.IO;
|
||
|
using System.Configuration;
|
||
|
using System.Threading;
|
||
|
namespace SiaSun.LMS.Common
|
||
|
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// ���н���֮����ת��������
|
||
|
/// Creator��Richard.liu
|
||
|
/// </summary>
|
||
|
public static class CCarryConvert
|
||
|
{
|
||
|
static Mutex mutex=new Mutex();
|
||
|
|
||
|
/// <summary>
|
||
|
/// ʮ����תʮ������
|
||
|
/// </summary>
|
||
|
/// <param name="dec">ʮ������</param>
|
||
|
/// <returns>ʮ�������ַ���</returns>
|
||
|
public static string DecimalToHex(byte dec)
|
||
|
{
|
||
|
return Convert.ToString(dec, 16);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ʮ����תʮ������
|
||
|
/// </summary>
|
||
|
/// <param name="dec"></param>
|
||
|
/// <returns></returns>
|
||
|
public static string DecimalToHex(int dec)
|
||
|
{
|
||
|
return Convert.ToString(dec, 16);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ʮ����ת�˽���
|
||
|
/// </summary>
|
||
|
/// <param name="dec">ʮ������</param>
|
||
|
/// <returns>�˽����ַ���</returns>
|
||
|
public static string DecimalToOct(byte dec)
|
||
|
{
|
||
|
return Convert.ToString(dec, 8);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ������תʮ����
|
||
|
/// </summary>
|
||
|
/// <param name="bin">�������ַ���</param>
|
||
|
/// <returns>ʮ������</returns>
|
||
|
public static Int32 BinToDecimal(string bin)
|
||
|
{
|
||
|
return Convert.ToInt32(bin, 2);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// �˽���תʮ����
|
||
|
/// </summary>
|
||
|
/// <param name="bin">�˽����ַ���</param>
|
||
|
/// <returns>ʮ������</returns>
|
||
|
public static Int32 OctToDecimal(string Oct)
|
||
|
{
|
||
|
return Convert.ToInt32(Oct , 8);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ʮ������תʮ����
|
||
|
/// </summary>
|
||
|
/// <param name="bin">ʮ�������ַ���</param>
|
||
|
/// <returns>ʮ������</returns>
|
||
|
public static Int32 HexToDecimal(string hex)
|
||
|
{
|
||
|
return Convert.ToInt32(hex , 16);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ʮ������ת�ֽ���ʮ����
|
||
|
/// </summary>
|
||
|
/// <param name="bin">ʮ�������ַ���</param>
|
||
|
/// <returns>�ֽ���ʮ������</returns>
|
||
|
public static byte HexToByte(string hex)
|
||
|
{
|
||
|
return Convert.ToByte(hex, 16);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ��ʮ����������ָ��bitλ�Ķ������ַ���0/1
|
||
|
/// </summary>
|
||
|
/// <param name="Int">ʮ������</param>
|
||
|
/// <param name="bitno">����λ</param>
|
||
|
/// <returns></returns>
|
||
|
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;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// byte[0]���Ÿ߰�λ,byte[1]���ŵͰ�λ
|
||
|
/// </summary>
|
||
|
/// <param name="_int16"></param>
|
||
|
/// <returns></returns>
|
||
|
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;
|
||
|
}
|
||
|
}
|
||
|
}
|