hexadecimal problem

Monkey Forums/Monkey Programming/hexadecimal problem

Dima(Posted 2013) [#1]
Greetings,

I am having some problems using hex literals to generate ARGB pixel color. Using Monkey v67d I get this result in HTML5:

Print($000000AA) ' result is 170 but should be 255

Basically $AAAAAAAA does not produce a white opaque pixel, but this does: 255 Shl 24 + 255 Shl 16 + 255 Shl 8 + 255

Maybe I'm not fully understanding what happens to the sign of the integer, but how can 8 bits per channel be used with signed ints that only use 31 bits for data? Why does shifting left produces a white pixel (which is correct) but Print results show this:

Print($AAAAAAAA)
'result is -1431655766 (this is bugged probably)

Print(255 Shl 24 + 255 Shl 16 + 255 Shl 8 + 255)
'result is -1 but gives me correct pixel colors when used with WritePixels()

does the sign bit only get used when doing integer arithmetic and otherwise it's a 32bit integer? In that case this makes sense, but HEX literals still produce unwanted result.

Thanks in advance,
Dima


marksibly(Posted 2013) [#2]
Hi,

$AA *is* 170 (10 * 16 + 10) : $FF is 255.


Dima(Posted 2013) [#3]
Doh, I'm very sorry about that, sleep derived. Going to leave my stupidity for everyone to see.

Thanks Mark!

p.s. Why on earth did I focus so much on discovering a bug, that I completely ignored the fact that $AA is not 255, even though I have been fully aware of that for the longest time. Don't let this happen to you guys - take care of your body and mind.


Jesse(Posted 2013) [#4]
Haha!
I have moments like that when I stay too long trying to solve a problem. I have to leave the computer and do other things. Usually when I am away a thought would come to my head on its own then I get an aww moment that completely solves my problem.


rIKmAN(Posted 2013) [#5]
Dima....pass me the joint lol!


c.k.(Posted 2013) [#6]
LOL! Dima, it happens to us all. I wonder how many of us read this without catching it!!! :-)