My wish for the next version of PB is a old BASIC command.
HEX2DEC ()
I have'nt found this command in PB.
Please..... For the next version...VERY important !
[Implemented] Classical BASIC Command HEX2DEC()
- Hroudtwolf
- Addict
- Posts: 803
- Joined: Sat Feb 12, 2005 3:35 am
- Location: Germany(Hessen)
- Contact:
- Hroudtwolf
- Addict
- Posts: 803
- Joined: Sat Feb 12, 2005 3:35 am
- Location: Germany(Hessen)
- Contact:
no userlib, just code... and it will take binary % hex $ octal %O and whatever you can come up with 

Code: Select all
Procedure.l x_val(string.s)
Global x_val_type.l
Protected p.l, l.l, b.l, t.l, c.l, s.l, m.l, p0.l
;
; *** as normal val() except it accepts also &H &O &0 &B % \ $ 0X
;
string = UCase(Trim(string))
l = Len(string)
p = @string
p0 = p
s = PeekB(p) & $FF
t = 0
;
If s = '-'
m = -1
p = p+1
s = PeekB(p) & $FF
Else
m = 1
If s = '+'
p = p+1
s = PeekB(p) & $FF
EndIf
EndIf
;
If s = '$'
p = p+1
b = 16
ElseIf s = '%'
p = p+1
b = 2
ElseIf s = '\'
p = p+1
b = 8
ElseIf Left(string,2) = "&B"
p = p+2
b = 2
ElseIf Left(string,2) = "&O"
p = p+2
b = 8
ElseIf Left(string,2) = "&0"
p = p+2
b = 8
ElseIf Left(string,2) = "&H"
p = p+2
b = 16
ElseIf Left(string,2) = "0X"
p = p+2
b = 16
;
; ElseIf Left(string,1) = "0" ; i don't like this one, as i often use
; p = p+1 ; preceding zeroes in front of decimals while
; b = 8 ; c(++) would turn those into octals... brrr...
; ; well, it's up to you to uncomment these lines
Else
b = 10
EndIf
;
While p < p0+l
c = (PeekB(p) & $FF) - 48
p = p+1
If c > 9
c = c - 7
EndIf
If c >= 0 And c < b
t = t*b+c
Else
p = p+l
EndIf
Wend
t = t * m
x_val_type = b
;
ProcedureReturn t
EndProcedure
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
- Hroudtwolf
- Addict
- Posts: 803
- Joined: Sat Feb 12, 2005 3:35 am
- Location: Germany(Hessen)
- Contact:
I won't comment on your statement about 'complete basic' but PureBasic costs EUR 59,-Hroudtwolf wrote:thx....
I know it to make this funtion by myself.
But ... PB costs 79 EURO. I mean, i could get a complete BASIC for this money.
Good programmers don't comment their code. It was hard to write, should be hard to read.
- Hroudtwolf
- Addict
- Posts: 803
- Joined: Sat Feb 12, 2005 3:35 am
- Location: Germany(Hessen)
- Contact: