[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Fwd: Need help on gambas function
[Thread Prev] | [Thread Next]
- Subject: Re: Fwd: Need help on gambas function
- From: Gianluigi <gradobag@xxxxxxxxxxx>
- Date: Wed, 18 Dec 2024 14:08:04 +0100
- To: user@xxxxxxxxxxxxxxxxxxxxxx
Il 18/12/24 12:13, Fabien Bodard ha scritto:
---------- Forwarded message --------- De : *Fabien Bodard* <gambas.fr@xxxxxxxxx <mailto:gambas.fr@xxxxxxxxx>> Date: mar. 17 déc. 2024 à 11:23 Subject: Need help on gambas function To: Fabien Bodard (Greumbeule) <gambas.fr@xxxxxxxxx <mailto:gambas.fr@xxxxxxxxx>> Hi to all In gambas you can : s = Hex(iInt) And print Cint("&H" & S) Give you back the int Well now I Want : Base(iInt, 36) How can I get My integer back ... in gambas "native" ? Is there an UnBase function ? Thank you :-) Public Sub Base36Decoder(Value As String) As Long Dim lResult As Long Dim iDigitVal, i As Integer Dim aNum As Byte[] = Byte[].FromString(UCase(Value)).Reverse() For i = 0 To aNum.Max iDigitVal = IIf(aNum[i] >= Asc("0") And aNum[i] <= Asc("9"), aNum[i] - 48, aNum[i] - 55) lResult += iDigitVal * (36 ^ i) Next Return lResult End -- Fabien Bodard -- Fabien Bodard
Hi Fabien, I think you were already told by Jussi, I guess you don't have to use IIF which tries both combinations. Public Sub Base36Decoder(Value As String) As Long Dim lResult As Long Dim iDigitVal, i As Integer Dim aNum As Byte[] = Byte[].FromString(UCase(Value)).Reverse() For i = 0 To aNum.Max 'iDigitVal = IIf(aNum[i] >= Asc("0") And aNum[i] <= Asc("9"), aNum[i] - 48, aNum[i] - 55) If aNum[i] >= Asc("0") And aNum[i] <= Asc("9") Then iDigitVal = aNum[i] - 48 Else iDigitVal = aNum[i] - 55 Endif lResult += iDigitVal * (36 ^ i) Next Return lResult End Regards Gianluigi
Fwd: Need help on gambas function | Fabien Bodard <gambas.fr@xxxxxxxxx> |