B4X:

```
Public Sub HexToColor(Hex As String) As Int
Dim bc As ByteConverter
If Hex.StartsWith("#") Then
Hex = Hex.SubString(1)
Else If Hex.StartsWith("0x") Then
Hex = Hex.SubString(2)
End If
If Hex.Length = 6 Then
Hex = "FF" & Hex
End If
Dim ints() As Int = bc.IntsFromBytes(bc.HexToBytes(Hex))
Return ints(0)
End Sub
```