Page 1 of 1
[Implemented] Classical BASIC Command HEX2DEC()
Posted: Thu Mar 03, 2005 5:49 pm
by Hroudtwolf
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 !
Posted: Thu Mar 03, 2005 6:58 pm
by Bonne_den_kule
Posted: Thu Mar 03, 2005 8:11 pm
by Hroudtwolf
Yes thx..I know a lot of userlibs for it.
But i think , this function must be included in PureBasic.
Not everyone knows this userlibs.
Posted: Thu Mar 03, 2005 10:33 pm
by blueznl
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
Posted: Thu Mar 03, 2005 10:47 pm
by Hroudtwolf
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.
Posted: Thu Mar 03, 2005 10:49 pm
by Rescator
Um it's 59 euros.
And afaik PureBasic is one of the most affordable programming languages out there!
Posted: Thu Mar 03, 2005 10:50 pm
by traumatic
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.
I won't comment on your statement about 'complete basic' but PureBasic costs
EUR 59,-
Posted: Thu Mar 03, 2005 10:53 pm
by Hroudtwolf
Sorry.,yes it was 59 Euros. My fingers often flying to fast over the keyboard.

Posted: Fri Mar 04, 2005 1:37 am
by PB
> i could get a complete BASIC for this money
But it would be nowhere near as good as PureBasic.
Sure, PureBasic lacks some commands now, but Fred takes good notes.
