问题描述
下面的是一段c#的代码.请大牛帮忙转成java的.跪谢publicstringGetHexChar(stringvalue){stringsReturn=string.Empty;switch(value){case"10":sReturn="A";break;case"11":sReturn="B";break;case"12":sReturn="C";break;case"13":sReturn="D";break;case"14":sReturn="E";break;case"15":sReturn="F";break;default:sReturn=value;break;}returnsReturn;}//将10进制字符串转化为16进制字符串publicstringConvertHex(stringvalue){stringsReturn=string.Empty;try{while(int.Parse(value)>16){intv=int.Parse(value);sReturn=GetHexChar((v%16).ToString())+sReturn;value=Math.Floor(Convert.ToDouble(v/16)).ToString();}sReturn=GetHexChar(value)+sReturn;if(sReturn.Length==1)sReturn="0"+sReturn;}catch{return"00";}returnsReturn;}publicvoidCreateHZ(stringIMSI,stringX,stringY,stringspeed,stringGPS_Dir){try{Socketsck_Client=Connect_Server();stringstrTel=IMSI.Trim();byte[]bt_Tel=newbyte[16];inti=0;for(i=0;i<strTel.Length;i++){stringstrEach=strTel.Substring(i,1);intiEach=Int32.Parse(strEach);iEach=48+iEach;bt_Tel[i]=(byte)iEach;}if(strTel.Length<16){for(intj=0;j<16-strTel.Length;j++)bt_Tel[i+j]=0;}stringstrLon=X.Trim();doubledLon=Double.Parse(strLon);dLon=dLon*648000000/180;intiLon=Convert.ToInt32(dLon);stringstrILon=iLon.ToString();stringstrHexLon=ConvertHex(strILon);if(strHexLon.Length==7)strHexLon="0"+strHexLon;stringstrHL1=strHexLon.Substring(0,2);intiHL1=Convert.ToInt32(strHL1,16);bytebtHL1=(byte)iHL1;stringstrHL2=strHexLon.Substring(2,2);intiHL2=Convert.ToInt32(strHL2,16);//if(iHL2>128)//iHL2=iHL2-128;bytebtHL2=(byte)iHL2;stringstrHL3=strHexLon.Substring(4,2);intiHL3=Convert.ToInt32(strHL3,16);//if(iHL3>128)//iHL3=iHL3-128;bytebtHL3=(byte)iHL3;stringstrHL4=strHexLon.Substring(6,2);intiHL4=Convert.ToInt32(strHL4,16);bytebtHL4=(byte)iHL4;stringstrLat=Y.Trim();doubledLat=Double.Parse(strLat);dLat=dLat*324000000/90;intiLat=Convert.ToInt32(dLat);stringstrILat=iLat.ToString();stringstrHexLat=ConvertHex(strILat);if(strHexLat.Length==7)strHexLat="0"+strHexLat;stringstrHA1=strHexLat.Substring(0,2);intiHA1=Convert.ToInt32(strHA1,16);bytebtHA1=(byte)iHA1;stringstrHA2=strHexLat.Substring(2,2);intiHA2=Convert.ToInt32(strHA2,16);//if(iHA2>128)//iHA2=iHA2-128;bytebtHA2=(byte)iHA2;stringstrHA3=strHexLat.Substring(4,2);intiHA3=Convert.ToInt32(strHA3,16);bytebtHA3=(byte)iHA3;stringstrHA4=strHexLat.Substring(6,2);intiHA4=Convert.ToInt32(strHA4,16);//if(iHA4>128)//iHA4=iHA4-128;bytebtHA4=(byte)iHA4;stringstrYear=DateTime.Now.AddHours(-8).Year.ToString();bytebt_Year=0;if(strYear.Length==4){strYear=strYear.Substring(2,2);stringstrYear1=strYear.Substring(0,1);if(strYear1=="0"){strYear=strYear.Substring(1,1);}intiYear=Convert.ToInt32(strYear);bt_Year=(byte)iYear;}stringstrMonth=DateTime.Now.AddHours(-8).Month.ToString();bytebt_Month=0;intiMonth=Convert.ToInt32(strMonth);bt_Month=(byte)iMonth;stringstrDay=DateTime.Now.AddHours(-8).Day.ToString();bytebt_Day=0;intiDay=Convert.ToInt32(strDay);bt_Day=(byte)iDay;stringstrH=DateTime.Now.AddHours(-8).Hour.ToString();bytebt_Hour=0;intiHour=Convert.ToInt32(strH);bt_Hour=(byte)iHour;stringstrM=DateTime.Now.AddHours(-8).Minute.ToString();intiMin=Convert.ToInt32(strM);bytebt_Min=(byte)iMin;stringstrS=DateTime.Now.AddHours(-8).Second.ToString();intiSec=Convert.ToInt32(strS);bytebt_Sec=(byte)iSec;stringstrSpeed=speed.Trim();doubledSpeed=Convert.ToDouble(strSpeed);intiSpeed=0;if(dSpeed<=1)iSpeed=1;elseif(dSpeed>1)iSpeed=(int)dSpeed;intiSp1=0;intiSp2=0;if(iSpeed>255){iSp1=iSpeed/256;}iSp2=iSpeed-iSp1*256;bytebt_Sp1=(byte)iSp1;bytebt_Sp2=(byte)iSp2;stringstrDirect=GPS_Dir;doubledDirect=100*Convert.ToDouble(strDirect);intiDirect=(int)dDirect;intiDir1=0;intiDir2=0;if(iDirect>255){iDir1=iDirect/256;}iDir2=iDirect-iDir1*256;bytebt_Dir1=(byte)iDir1;bytebt_Dir2=(byte)iDir2;if(sck_Client!=null){byte[]byteData={35,35,85,83,101,bt_Tel[0],bt_Tel[1],bt_Tel[2],bt_Tel[3],bt_Tel[4],bt_Tel[5],bt_Tel[6],bt_Tel[7],bt_Tel[8],bt_Tel[9],bt_Tel[10],bt_Tel[11],bt_Tel[12],bt_Tel[13],bt_Tel[14],bt_Tel[15],99,00,22,00,00,00,33,bt_Year,bt_Month,bt_Day,bt_Hour,bt_Min,bt_Sec,btHL1,btHL2,btHL3,btHL4,btHA1,btHA2,btHA3,btHA4,bt_Sp1,bt_Sp2,bt_Dir1,bt_Dir2,13,10};//stringstrSend=Encoding.ASCII.GetString//byte[]byteMessage=Encoding.GetEncoding("gb2312").GetBytes(strSend);sck_Client.Send(byteData,byteData.Length,SocketFlags.None);byte[]recvBytes=newbyte[8000];sck_Client.Shutdown(SocketShutdown.Both);sck_Client.Close();}}catch(Exceptionexp){stringstrExp=exp.Message.ToString();return;}}}}