欢迎来到天天文库
浏览记录
ID:50989914
大小:76.00 KB
页数:19页
时间:2020-03-08
《C#数据格式转换函数集合.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、常用数据格式转换函数集合usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceLaisonTech.CommonBLL{//////数据类型转换///publicclassDataFormatProcessor{publicconstByteASCII_0=48;publicconstByteASCII_9=57;publicconstByteASCII_A=65;publicconstByteASCII_F=70;publi
2、cconstByteASCII_Z=90;publicconstByteASCII_a=97;publicconstByteASCII_f=102;publicconstByteASCII_z=122;//////字节转换为字符串/////////publicstaticStringByteToHexChar(Byteval){returnval.ToString("X2");}//////字节转换为字符串
3、/////////publicstaticStringByteToBitString(Byteval){if(val==0){return"00000000";}if(val==255){return"11111111";}Stringret=String.Empty;Int32bitval=0;for(intbitidx=7;bitidx>-1;--bitidx){bitval=val&(1<0){re
4、t=ret+"1";}else{ret=ret+"0";}}returnret;}//////2个HEX字符转换为1个字节数组//////"A1"///161///publicstaticBooleanHexStringToByte(Stringhexstr,outBytebyteval){byteval=0;if(hexstr.Length!=2){returnf
5、alse;}byteval=Convert.ToByte(hexstr,16);returntrue;}//////HEX字符串转换为字节数组////////////publicstaticBooleanHexStringToBytes(Stringhexstr,outByte[]bytes){bytes=null;if((hexstr==null)
6、
7、(hexst
8、r.Length<2)){returnfalse;}if(hexstr.Length%2==1){returnfalse;}intbytelen=hexstr.Length/2;if(bytelen<1){returnfalse;}bytes=newByte[bytelen];Stringcurbytestr=String.Empty;for(intbidx=0;bidx9、onvert.ToByte(curbytestr,16);}if(bytes==null10、11、bytes.Length<1){returnfalse;}returntrue;}//////HEX字符串转换为字节数组////////////publicstaticBooleanHexStringToBytesWithSplitter(Stringhexstr,outBy12、te[]bytes){bytes=null;if(hexstr==null13、14、hexstr.Length<2){retur
9、onvert.ToByte(curbytestr,16);}if(bytes==null
10、
11、bytes.Length<1){returnfalse;}returntrue;}//////HEX字符串转换为字节数组////////////publicstaticBooleanHexStringToBytesWithSplitter(Stringhexstr,outBy
12、te[]bytes){bytes=null;if(hexstr==null
13、
14、hexstr.Length<2){retur
此文档下载收益归作者所有