1、將一個(gè)對(duì)象轉(zhuǎn)換為byte對(duì)象
public static byte GetByte(object o){byte retInt = 0;if (o != null){byte tmp;if (byte.TryParse(o.ToString().Trim(), out tmp)){retInt = tmp;}}return retInt;} 2、將一個(gè)十六進(jìn)制字符串轉(zhuǎn)換為byte對(duì)象,字符串以0x開頭
public static byte GetByteFormHex(string hexValue){try{return Convert.ToByte(hexValue, 16);}catch {return 0;}}3、將單個(gè)字符轉(zhuǎn)換為byte對(duì)象
public static byte GetByteFormSingleString(string value){return GetByteFormChar(Convert.ToChar(value));}4、將一個(gè)字符串轉(zhuǎn)換為byte數(shù)組
public static byte[] GetBytes(string values){return System.Text.Encoding.Default.GetBytes(values);}以上內(nèi)容是小編給大家介紹的C#中Byte轉(zhuǎn)換相關(guān)的函數(shù),希望對(duì)大家有所幫助!
新聞熱點(diǎn)
疑難解答
圖片精選