问题
I am working on a BlackBerry app. This app has already been developed in Android in "Basic4Android" program. The code for the android app is written in vb.net. I need to write the exact same code for BlackBerry. I am trying to understand this method but I am unable to since I am not an expert with vb.net. I will not paste the entire method but only parts which I need to clarify:
Sub HEX_T24_SHORT_GPS(latitude_decimal_degrees As Double, longitude_decimal_degrees As Double, speed_knots As Int, heading_degrees As Int, time_seconds_since_midnight_gmt As Int, alert_on As Boolean, alert_ack As Boolean, external_interface_control As Boolean, send_extended As Boolean) As String
Dim pBuffer(11) As Int
pBuffer(0)=0 ' T24 MSGID 0
Log("pBuffer(2)" & pBuffer(2))
Dim t1 As Double
'Get latitude sign
Dim lat_south As Boolean
lat_south=True
If latitude_decimal_degrees<0 Then lat_south=False
'Get Longitude sign
Dim lon_west As Boolean
lon_west=True
If longitude_decimal_degrees<0 Then lon_west=False
'Get number of second since midnigh extra bit
Dim num_of_second_extra_bit As Boolean
num_of_second_extra_bit=False
If time_seconds_since_midnight_gmt > 0xFFFF Then num_of_second_extra_bit=True
'Convert latitude in bytes 1 to 3
latitude_decimal_degrees = Abs(latitude_decimal_degrees*60000)
What does "If time_seconds_since_midnight_gmt > 0xFFFF" mean? What is happening here "latitude_decimal_degrees = Abs(latitude_decimal_degrees*60000)". I checked the "Basic4Android" documentation but could not find the Abs API.
If num_of_second_extra_bit=True Then latitude_decimal_degrees=latitude_decimal_degrees + 0x800000
pBuffer(1)=Bit.ShiftRight(Bit.And(latitude_decimal_degrees, 0xFF0000),16)
pBuffer(2)=Bit.ShiftRight(Bit.And(latitude_decimal_degrees, 0x00FF00),8)
pBuffer(3)=Bit.And(latitude_decimal_degrees, 0xFF)
How is the bit shift applied? Is the "AND" operation used between an int and hex value? What is the final value in pBuffer(1)? What is the purpose of steps pBuffer(1) to pBuffer(3). What is it doing and what is the final value of latitude_decimal_degrees?Is the final value in bytes, byte array or hex?Please explain.
回答1:
What does "If time_seconds_since_midnight_gmt > 0xFFFF" mean?
What this does is checking if the time_seconds_since_midnight_gmt is bigger than 65,535 - this is probably some sort of compensation - remember there's 86,400 seconds in a day.
What is happening here "latitude_decimal_degrees = Abs(latitude_decimal_degrees*60000)"
The decimal part of the latitude is being multiplied by 60,000 - this is pretty much context based what's going on - it's probably has something to do with the speed you are moving in - you should look into where this function is called from and try to figure out what the number range is that is going into this variable, and then try to deduce it from that.
How is the bit shift applied?
First 0x800000 is added (this is setting bit number 23 high)
Is the "AND" operation used between an int and hex value?
Yes. It seems like you're mixing things up - an integer value can be repesented in base 2 (binary), base 8 (octal), base 10(the usual way) and base 16 (hexadecimal) - it's still the same value.
What is the final value in pBuffer(1)? Please explain.
Okay - let's run through an example:
latitude_decimal_degrees = 0xE653 (58,963)
then add 0x800000
latitude = 0x80E653
then and with 0xFF0000
latitude = 0x800000
and finally right shift by 16
latitude = 0x000080
What this means on the other hand, is up for your interpretation.
来源:https://stackoverflow.com/questions/13798383/vb-net-code-for-android-app