I have a latitude value as double and I want to perform a Bitwise AND operation on it followed by right shift of bits. Following is my line of code:
pBuffer[1]=(latitude_decimal_degrees & 0xFF0000) >> 16;
However a Bitwise AND operation between a double and int value is not possible. I cannot convert the latitude to int as this would not yield an accurate value. Can anybody guide me in this?
EDIT: My requirement is basically to translate the following vb.net code into java. Reason: The lines of code below (vb.net) is part of a method written in "Basic4Android" for an android app. The exact same method is to be implement in my BlackBerry App. Therefore I need to have the exact same value generated as below which will be decoded at the server end:
Dim pBuffer(11) As Int
Dim longitude_decimal_degrees As Double
pBuffer(1)=Bit.ShiftRight(Bit.And(latitude_decimal_degrees, 0xFF0000),16)
How can these lines of code be translated into java?
解决方案
You can turn the double into a long via bits using Double.doubleToRawLongBits(latitude_decimal_degrees) perform all bitwise operations in the long space, then convert back to a double via longBitsToDouble