Hi all,
Is there a function to convert hex to integer value (decimal value)>> there are some but I though maybe some has a better solution with simple and shorter function.
Do you mean converting hex string to int?
Maybe ByteConverter can do this. HexToBytes (hex As String) As Byte() IntsFromBytes (bytes() As Byte) As Int()
Hi teddybear, Thanks but I thought Byte is Hex
I have a hex value in string (EditTex) and want to convert it to decimal.. (FF >> 256)
inline java is ok.
Sub HexToDecimal(hex As String) As Int
Try
Dim decimalValue As Int
decimalValue = Bit.ParseInt(hex, 16) ' Convert hex to decimal
Return decimalValue
Catch
Log("Error: Invalid Hexadecimal value")
Return -1
End Try
End Sub
I found this code snippet somewhere and want to reverse the conversion parts so the data is displayed as it comes in (not converted to Hex)
B4X:
Sub AStream_NewData (Buffer() As Byte)
Dim hexString As String = BytesToHex(Buffer)
ParseAndDisplayData(hexString)
End Sub
Sub BytesToHex(bytes() As Byte) As String
Dim sb As StringBuilder
sb.Initialize
For i = 0 To bytes.Length - 1
Dim intValue As Int = Bit.And(bytes(i), 0xFF) ' Safely convert byte to integer
Dim hexString As String = Bit.ToHexString(intValue).ToUpperCase ' Convert to uppercase hex
sb.Append(hexString).Append(" ")
Next
Return sb.ToString.Trim
End Sub
Sub ParseAndDisplayData(data As String)
Dim parsedData As String = data'.Replace("00", "00") ' Remove the "00" termination
If parsedData.Length > 0 Then
lblData.Text = parsedData
End If
End Sub
found, that sometimes it's easyer, to knit it up...:) private Sub intFromHex(b1() As Byte)As Int Dim in As Int 'send( JoinStrings(Array As String("b1 :", bc.StringFromBytes(b1))) ) 'test For i = 0 To b1.Length - 1 Dim m As Double = Power(16,b1.Length-1-i) ' multiplikator If b1(i)>60...
I can convert int to hex using Dim input As Int = 65535 Dim output As String output = Bit.ToHexString(input) Log(output) Please can someone suggest a way of converting back from Hex to string and explain it in a simplistic way so I can understand. I have tried...
"I feel like your next wondering will be why are Byte values are -128 to 127 rather than 0 to 255, and the solution is:"
In fact I finished this calculation in 1984 AD, 4682 in Chinese calendar and 1404 in Hijri calendar and 5744 in Jewish calendar. You do the arithmatic.
"I feel like your next wondering will be why are Byte values are -128 to 127 rather than 0 to 255, and the solution is:"
In fact I finished this calculation in 1984 AD, 4682 in Chinese calendar and 1404 in Hijri calendar and 5744 in Jewish calendar. You do the arithmatic.