使用public class toolclass
return crc_16;
}//modbus crc-16表 8005 逆序
private static ushort g_mcrctable_16 =;
/// /// 轉換ascii
///
///
public static string getascii(string ascii)
;return system.text.encoding.ascii.getstring(bufdata);
}/// /// string 轉 byte
///
///
///
public static byte str_change_byte(string str)
if (strsource.length % 2 != 0)//剩下一位單獨處理
}catch (exception)
byte buf = new byte[count];
array.copy(data, 0, buf, 0, count); //複製原始資料
return buf;
}// 1、數字和位元組之間互轉
//int num = 12345;
// byte bytes = bitconverter.getbytes(num);//將int32轉換為位元組陣列
// num=bitconverter.toint32(bytes,0);//將位元組陣列內容再轉成int32型別
//2、將字串轉為16進製制字元,允許中文
public static string stringtohexstring(string s, encoding encode)
return result;
}//如:
///注意,乙個中文轉為utf-8佔三個位元組,英文佔乙個位元組
"中華人民共和國",
//或使用
"中華人民共和國"))
//返回結果為xx-xx-xx
//然後再去掉"-"
////3、將16進製制字串轉為字串
public static string hexstringtostring(string hs, encoding encode)
//按照指定編碼將位元組陣列變為字串
return encode.getstring(b);
}//如:
//string hexstring = stringtohexstring("中華人民共和國", system.text.encoding.utf8);
// string content = hexstringtostring(hexstring, system.text.encoding.utf8)
//4、將byte 轉為16進製制字串
public static string bytetohexstr(byte bytes)
}return returnstr;
}//5、將16進製制的字串轉為byte
private static byte strtotohexbyte(string hexstring)
/// /// 轉16進製制10 textbox5.text = t
/" ", ""), 16, 10);
///
///
///
public static string convertnumber(string input,int typeoinput ,int typeofoutput)
}
/// /// 迴圈冗餘校驗
///
///
///
private void button1_click(object sender, eventargs e)
///asiic
private void button2_click(object sender, eventargs e)
private void button3_click(object sender, eventargs e)
catch (exception ex)
}
進製轉換(16轉8)
問題描述 給定n個十六進製制正整數,輸出它們對應的八進位制數。輸入格式 輸入的第一行為乙個正整數n 1 n 10 接下來n行,每行乙個由09 大寫字母af組成的字串,表示要轉換的十六進製制正整數,每個十六進製制數長度不超過100000。輸出格式 輸出n行,每行為輸入對應的八進位制正整數。注意 輸入的...
c 之進製轉換16進製制 10進製
本文講解一種在c 中如何將16進製制字串轉化成10進製,水平不高,但願對你有幫助。一下便是源程式,包涵檢錯以及轉化函式。前些日子幫乙個朋友做筆試題,結果因為不熟悉這塊的內容,只得了80分,自己好好安靜下來寫了一次,include include using namespace std void ch...
c 16進製制10進製轉換
十進位制轉二進位制 console.writeline convert.tostring 69,2 十進位制轉八進位制 console.writeline convert.tostring 69,8 十進位制轉十六進製制 console.writeline convert.tostring 69,1...