Page 1 of 2

Hex() PB Help is incomplete

Posted: Mon Mar 30, 2009 2:53 am
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?

Posted: Mon Mar 30, 2009 3:58 am
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.

Posted: Mon Mar 30, 2009 4:12 am
by ts-soft
There is no 3 :wink:
#PB_Integer is 2 on x86 and 4 on x64

Posted: Mon Mar 30, 2009 4:16 am
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).

Posted: Mon Mar 30, 2009 4:18 am
by netmaestro
hehe I'm a bit burned out! :D

Posted: Mon Mar 30, 2009 4:52 am
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

Posted: Mon Mar 30, 2009 5:00 am
by netmaestro
Rescued! :D

Posted: Mon Mar 30, 2009 7:44 am
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 :)

Posted: Mon Mar 30, 2009 10:26 am
by Psychophanta
ehem... and, ¿what about to move this to its place (i.e. the "coding question" section) ? :roll:

Posted: Mon Mar 30, 2009 10:59 am
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.

Posted: Mon Mar 30, 2009 1:07 pm
by PB
> Rescued! :D

:oops: Well it looked logical according to the values that were posted. ;)

Posted: Mon Mar 30, 2009 1:42 pm
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]

Posted: Mon Mar 30, 2009 2:31 pm
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:

Posted: Mon Mar 30, 2009 3:13 pm
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.

Posted: Mon Mar 30, 2009 8:56 pm
by Psychophanta
That is very true Kaeru.