Sub AppStart (Args() As String)
Log(ToBCD(150))
Log(FromBCD("000101010000"))
End Sub
Public Sub ToBCD (n As Int) As String
Dim sb As StringBuilder
sb.Initialize
Do While n > 0
Dim d As Int = n Mod 10
sb.Insert(0, ToHex(d, 4))
n = n / 10
Loop
Return sb.ToString
End Sub
Public Sub FromBCD(bcd As String) As Int
Dim n As Int
For i = 0 To bcd.Length - 4 Step 4
n = n * 10 + Bit.ParseInt(bcd.SubString2(i, i + 4), 2)
Next
Return n
End Sub
Private Sub ToHex(n As Int, NumberOfDigits As Int) As String
Dim res As String = Bit.ToBinaryString(n)
Do While res.Length < NumberOfDigits
res = "0" & res
Loop
Return res
End Sub