C#代码到JAVA代码 [英] C# code to JAVA code
问题描述
我付出了很多努力,谷歌搜索并尝试了所有可能的方法。但是我没有满意所以我最终来到这里。
我想将下面的代码[C#]转换成java。
1]用于将IP转换为uint的方法
private uint GetIP(string strIp)
{
System.Net.IPAddress ipaddress = System.Net.IPAddress.Parse(strIp);
uint lIp =(uint)ipaddress.Address;
lIp =((lIp& 0xFF000000)>> 24)+((lIp& 0x00FF0000)>> 8)+((lIp& 0x0000FF00)<< 8 )+((lIp& 0x000000FF)<< 24);
MessageBox.Show(strIp +=+ lIp);
return(lIp);
}
2]用于将String转换为IntPtr的方法
IntPtr iPtr = Marshal.StringToHGlobalAnsi(你好);
请尽快帮助我。提前致谢。
我非常感谢帮助。
我尝试了什么:
我试过以下代码将IP转换为Long,不确定是对还是错。
public static long ipToLong(String ipAddress){
String [] ipAddressInArray = ipAddress.split(\\。);
long result = 0;
for(int i = 0; i< ipAddressInArray.length; i ++){
int power = 3 - i;
int ip = Integer.parseInt(ipAddressInArray [i]);
result + = ip * Math.pow( 256,电源);
}
返回结果;
}
对于String到IntPtr,尝试将String转换为Ascii,然后尝试通过引用使用Intger。
请参阅 InetAddress(Java Platfo) rm SE 7) [ ^ ]。
I have put lot of efforts, googled and tried all possible ways. But I did not got satisfaction so I come here finally.
I want to convert below line of code [C#] into java.
1] Method used to convert IP into uint
private uint GetIP(string strIp) { System.Net.IPAddress ipaddress = System.Net.IPAddress.Parse(strIp); uint lIp = (uint)ipaddress.Address; lIp = ((lIp & 0xFF000000) >> 24) + ((lIp & 0x00FF0000) >> 8) + ((lIp & 0x0000FF00) << 8) + ((lIp & 0x000000FF) << 24); MessageBox.Show(strIp + " = " + lIp); return (lIp); }
2] Method used to convert String into IntPtr
IntPtr iPtr = Marshal.StringToHGlobalAnsi("Hello");
Please help me as soon as possible. Thanks in advance.
I really appreciate help.
What I have tried:
I have tried following code for converting IP to Long, not sure is it right or wrong .
public static long ipToLong(String ipAddress) {
String[] ipAddressInArray = ipAddress.split("\\.");
long result = 0;
for (int i = 0; i < ipAddressInArray.length; i++) {
int power = 3 - i;
int ip = Integer.parseInt(ipAddressInArray[i]);
result += ip * Math.pow(256, power);
}
return result;
}
For String to IntPtr, tried to convert String to Ascii and then tried to use Intger by reference.
See InetAddress (Java Platform SE 7 )[^].
这篇关于C#代码到JAVA代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!