String ntohl(int i)
{
int i1 = i % (256);
int i2 = (i %(65536))/(256);
int i3 = (i %(16777216))/(65536);
int i4 = (i)/(16777216);
int i5 = i % (2^8);
int i6 = (i %(2^16))/(2^8);
int i7 = (i %(2^24))/(2^16);
int i8 = i/(2^24);
Log.d(TAG, "i:"+i+" "+i1+"."+i2+"."+i3+"."+i4);
Log.d(TAG, "i:"+i+" "+i5+"."+i6+"."+i7+"."+i8);
return ""+i1+"."+i2+"."+i3+"."+i4;
}
Hi,
I have a method listed above which returns an ipv4 address. I’ve done the calculation however i5 i6 i7 i8 is not like i1 i2 i3 i4.
Using modulus can return negative numbers which you might not expect. Try using the following pattern