[Gambas-user] Octal to Integer Conversion
T Lee Davidson
t.lee.davidson at gmail.com
Thu Jan 25 17:08:58 CET 2018
While we're waiting for the Octal number representation issue to be resolved, I've coded up a little function that will convert
an octal number, represented as a string, to its correct integer representation.
[code]
Function OctStrToInt(Value As String, Optional Pow As Integer = 0) As Integer
Dim char As String
If Len(Value) = 1 Then
char = Value
Value = ""
Else
char = Right(Value, 1)
Value = Left(Value, -1)
Endif
If char < "0" Or "7" < char Then Error.Raise("Invalid octal character '" & char & "'")
If Value Then
Return CInt(char) * 8 ^ Pow + OctStrToInt(Value, Pow + 1)
Else
Return CInt(char) * 8 ^ Pow
Endif
End
[/code]
Use it like:
OctInt = OctStrToInt("644") ' yields 420
--
Lee
More information about the User
mailing list