[Implemented] Classical BASIC Command HEX2DEC()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

[Implemented] Classical BASIC Command HEX2DEC()

Post 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 !
Bonne_den_kule
Addict
Addict
Posts: 841
Joined: Mon Jun 07, 2004 7:10 pm

Post by Bonne_den_kule »

User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post 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.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post 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
( 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... )
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post 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.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

Um it's 59 euros.

And afaik PureBasic is one of the most affordable programming languages out there!
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post 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,-
Good programmers don't comment their code. It was hard to write, should be hard to read.
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

Sorry.,yes it was 59 Euros. My fingers often flying to fast over the keyboard. :D
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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. :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Post Reply