[Implemented] Val() and hex

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

[Implemented] Val() and hex

Post by BackupUser »

Restored from previous forum. Originally posted by freak.

Hi,

It would be nice, if Val() could also convert strings like "$FF", or "%11011"
to numbers.

Or what about adding something like ValHex(), and ValBin()

Timo

--

A debugged program is one for which you have not yet found the conditions that make it fail.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> Or what about adding something like ValHex(), and ValBin()

That would be handy. In the meantime, if you need hex, try this... call it
like so: dec=hex2dec(hex$).

Code: Select all

Procedure.l hex2dec(h$)
  ; h$ can be 0-FFFFFFF.
  h$=UCase(h$)
  For r=1 To Len(h$)
    d60
      d+Asc(a$)-55
    Else
      d+Asc(a$)-48
    EndIf
  Next
  ProcedureReturn d
EndProcedure

PB - Registered PureBasic Coder

Edited by - PB on 09 May 2002 23:20:41
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by freak.

Thanks PB! Works fine.

Timo

--

A debugged program is one for which you have not yet found the conditions that make it fail.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tinman.
> Or what about adding something like ValHex(), and ValBin()

That would be handy. In the meantime, if you need hex, try this... call it
like so: dec=hex2dec(hex$).
There's a command in the StringLibraryEx 3rd party lib called exactly that :)


--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + SP1, PB3.10)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by freak.

Well, you're right. I should have looked at Paul's site before posting this



--

A debugged program is one for which you have not yet found the conditions that make it fail.
Post Reply