confused

BlitzMax Forums/BlitzMax Programming/confused

Nigel Brown(Posted 2005) [#1]
Global c:Byte = $55

Print Hex(c)
Print Byte(Hex(c & $FF))

c = ~c

Print Hex(c)
Print Byte(Hex(c & $FF))

ANS:
00000055
55
000000AA
0

I dont understand why the 000000AA has become 0? OK $AA has top bit set makes it negative? HELP!


Shambler(Posted 2005) [#2]
Its because Hex is returning a string and not a numeric value.

$55 gets converted to 55...an error really since $55 doesn't equal decimal 55, BMax is just trying to let you do what you tell it ;)
$AA gets converted to 0 since A means nothing in decimal.

Remember that 'Byte' does not imply any ability to convert a value from Hex into decimal.


Yan(Posted 2005) [#3]
Remember that 'Byte' does not imply any ability to convert a value from Hex into decimal.
That's not entirely true. It's just that Byte() doesn't know the string is supposed to be a hexadecimal number and converts it to 0 (well, doesn't convert it really).
You can can, however, give it a helping hand...
 Global c:Byte = $55

Print Hex(c)
Print Byte("$" + Hex(c & $FF)) ' BMax coolness in action :o)

c = ~c

Print Hex(c)
Print Byte("$" + Hex(c & $FF))
Although why you'd want to, when you can just use...
Print c
...is beyond me?

[edit]
Did you mean this...
Print RSet(Hex(c), 2)
'Print Hex(c)[Hex(c).length - 2..] ' More BMax fun :o)
??
[/edit]


Also, BYTE is unsigned...