Hex() PB Help is incomplete

Everything else that doesn't fall into one of the other PB categories.
jack
Addict
Addict
Posts: 1359
Joined: Fri Apr 25, 2003 11:10 pm

Hex() PB Help is incomplete

Post by jack »

the help file does not explain the usage well or I am missing something, when you type Hex(variable the hint at the bottom of the IDE shows Hex(Number [,Type])
I tried w, word, l, long for the type but it's ignored however by trial I found that if I use 0 for byte, 1 for word, 2 for long and 3 for quad it works as expected.
are the some constants somewhere that define the types?
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8453
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

They're all in the structure viewer under the "Constants" tab, #PB_Byte=0, #PB_Word=1, #PB_Long=2, #PB_Quad=4. Dunno what 3 is.
BERESHEIT
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

There is no 3 :wink:
#PB_Integer is 2 on x86 and 4 on x64
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

@netmaestro: Come on now, you know better than that! :)
The flags are just doubling in value as they go (0, 1, 2, 4).
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8453
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

hehe I'm a bit burned out! :D
BERESHEIT
freak
PureBasic Team
PureBasic Team
Posts: 5962
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

PB wrote:@netmaestro: Come on now, you know better than that! :)
The flags are just doubling in value as they go (0, 1, 2, 4).
Not quite... ;)

Code: Select all

#PB_Byte      = 0
#PB_Word      = 1
#PB_Long      = 2
#PB_Float     = 3
#PB_Quad      = 4
#PB_String    = 5
#PB_Double    = 6
#PB_Character = 7

CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
  #PB_Integer = #PB_Quad
CompilerElse
  #PB_Integer = #PB_Long
CompilerEndIf
quidquid Latine dictum sit altum videtur
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8453
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Rescued! :D
BERESHEIT
User avatar
Comtois
Addict
Addict
Posts: 1433
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post by Comtois »

What is exactly #PB_String? when should I use it ?

Code: Select all

Debug Hex(12,#PB_String)
[EDIT]
I assume that this constant is not provided for the Hex () ?

What constants are used for the Hex() ? I ask it to update the French doc :)
Please correct my english
http://purebasic.developpez.com/
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

ehem... and, ¿what about to move this to its place (i.e. the "coding question" section) ? :roll:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

@Comtois

only #PB_Byte, #PB_Word, #PB_Long, #PB_Quad and #PB_Integer make sense to use with Hex()

the other constants are implemented to provide type describing constants for ANY function that would need it...


@freak

as there is a flag to determine the length for the returned string now,
it would be nice if it would also contain leading zeros.
when you want a hexadezimal string, you (almost) always want leading zeros.
oh... and have a nice day.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> Rescued! :D

:oops: Well it looked logical according to the values that were posted. ;)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
jack
Addict
Addict
Posts: 1359
Joined: Fri Apr 25, 2003 11:10 pm

Post by jack »

thanks guys, I was looking for constants in the constant viewer but looking for #WORD etc.

[edit] why not include float and double for the Hex function?
presently you would have to do something like this

Code: Select all

Structure MyDbl
  StructureUnion
    d.d
    q.q
  EndStructureUnion
EndStructure

n.MyDbl
n\d=1.234
Debug Hex(n\q,4)
[/edit]
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

oh oh, that's not well done.
Where is the floating point in the result?
And moreover, the result is totally wrong, AND it is the same if you replace "4" by #PB_Double :wink:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

I don't think it woild make ANY sense to display a floating point number in hexadecimal or binary...

I mean, hey, who the heck could read something like 3 BC 4F.5F 3C ?
(what would be around 244 815.372 009 277 343 75 if I got it right)

Hexadecimal is a useful notation because it has an integer relation of digits to bytes.
two digits per byte. thats it.

for fractions, humans are used to their native number's base, ten, the decimal notation.

... and yes, your "result" could be called "wrong", because you just show the bitwise translation of floating point storage, but not a hexadecimal fraction.
oh... and have a nice day.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

That is very true Kaeru.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply