B4J Question Integer to Hex & longTo Hex

rgarnett1955

Active Member
Licensed User
Longtime User
Hi,

I had to log out some integers for colors whilst debugging. I couldn't seem to find anything suitable so I wrote a small class.

I'm not too sure whether it is valid or the most efficient way of doing this.

Could someone have a look at it and see whether it's OK.

intToHex and longToHex:
Sub Class_Globals
    Private fx As JFX
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize

End Sub


'======================================================================================
public Sub intToHex(i As Int, Prefix As String) As String
    Dim bc As ByteConverter
    Dim iArray(1) As Int
    iArray(0) = i
    Dim remBytes(4) As Byte = bc.IntsToBytes(iArray)

    Return   Prefix & bc.HexFromBytes(remBytes)
End Sub

'======================================================================================
public Sub longToHex(i As Long, Prefix As String) As String
    Dim bc As ByteConverter
    Dim iArray(1) As Int
    iArray(0) = i
    Dim remBytes(8) As Byte = bc.IntsToBytes(iArray)

    Return   Prefix & bc.HexFromBytes(remBytes)
End Sub

'====================================== EOF ===========================================

Best regards
Rob
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…