[Gambas-user] Octal to Integer Conversion
Yahoo
olivier.cruilles at yahoo.fr
Thu Jan 25 21:12:41 CET 2018
Thank you Lee, now less dependency of C Library. Tested and it works fine.
Olivier
Le January 25, 2018 à 11:10:04, T Lee Davidson (t.lee.davidson at gmail.com) a écrit:
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
--------------------------------------------------
This is the Gambas Mailing List
https://lists.gambas-basic.org/listinfo/user
Hosted by https://www.hostsharing.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180125/2f1890ed/attachment.html>
More information about the User
mailing list