Working on a wireless BT telescope controller that converts angles (right ascension and declination)
to an 8 digits hex string with two trailing zeros for a telescope to slew towards, say, a star.
The above routine works perfectly for most angles, but around x = 165 it gives wrong results.
The routine is the same as the one I once used with Basic4ppc, employing "hexra=bit.DecToHex(x)" with
no issues at all.
This raises the question whether "Bit.ToHexString" in B4A could contain a bug, such as omission of a leading
zero in a hex string. Or, my choice of conversion to Hex is a wrong one.
Cheers
Robert
to an 8 digits hex string with two trailing zeros for a telescope to slew towards, say, a star.
B4X:
Sub Deg2Hex(x As Double, y As Double, grid As String) As String
Dim hexra, hexde As String
x = Round(x * 46603.378)
y = Round(y * 46603.378)
If y < 0 Then y = 16777216 + y
hexra = Bit.ToHexString(x) & "00000000"
hexra = hexra.SubString2(0,8).ToUpperCase
hexde = Bit.ToHexString(y) & "00000000"
hexde = hexde.SubString2(0,8).ToUpperCase
Select grid
Case "eqt"
Return "r" & hexra & "," & hexde
Case "azm"
Return "b" & hexra & "," & hexde
End Select
End Sub
The routine is the same as the one I once used with Basic4ppc, employing "hexra=bit.DecToHex(x)" with
no issues at all.
This raises the question whether "Bit.ToHexString" in B4A could contain a bug, such as omission of a leading
zero in a hex string. Or, my choice of conversion to Hex is a wrong one.
Cheers
Robert