# Hex values as ints?

• 07-22-2012, 01:34 AM
nhmllr
Hex values as ints?
I'm trying to loads game maps into my game my making a .png in MS Paint, where each pixel represents a kind of block
So I'm able to load the image, and I can get the RGB values into an array of ints

Now, I want to change these ints. For example the floor, represented by a black pixel, should be changed into int value 0.
A wall is pure white, and should be 1.

So I said

Code:

```private final int FLOOR_COL = 0x000000; private final int WALL_COL = 0xFFFFFF; private final int FLOOR_INT = 0; private final int WALL_INT = 1;```
Then after I get the array of ints, I transmute it like this (it's in a for loop that cycles through the row/col values)
Code:

```switch(map[row][col]) {     case FLOOR_COL: map[row][col] = FLOOR_INT; break;     case WALL_COL: map[row][col] = WALL_INT; break; }```
Then I went to print it out. I didn't see a bunch of 0's and 1's printed out in a box, however. What I saw was a bunch of digits, all negative. Some of them were -1, some of them were -16777216
...Why?

I am 100% sure that all pixels are either pure white or pure black.
When I declare
Code:

```private final int FLOOR_COL = -1; private final int WALL_COL = -16777216;```
It works as intended.

So... what?
I get the RGB values from this method

Is it a different kind of RGB value? I don't understand.

Thanks
• 07-22-2012, 02:42 AM
eRaaaa
Re: Hex values as ints?
There is an alpha value...
Try case 0xff000000 | FLOOR_COL: and case 0xff000000 | WALL_COL:
The rgb components are in the bits 0-23, the alpah value is in the bits 24-31
• 07-22-2012, 07:42 AM
nhmllr
Re: Hex values as ints?
Ah, that worked. I put "FF" in front of every color (I had more but I didn't want to confuse the issue) and everything worked. Thanks