Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By eRaaaa

Thread: Hex values as ints?

  1. #1
    nhmllr's Avatar
    nhmllr is offline Member
    Join Date
    Aug 2011
    Posts
    51
    Rep Power
    0

    Default 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

    Java 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)
    Java 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
    Java 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
    Last edited by nhmllr; 07-22-2012 at 12:37 AM.

  2. #2
    eRaaaa is online now Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default 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
    Fubarable likes this.

  3. #3
    nhmllr's Avatar
    nhmllr is offline Member
    Join Date
    Aug 2011
    Posts
    51
    Rep Power
    0

    Default 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

Similar Threads

  1. Identifying Ints and Non Ints in a string
    By Mnelson in forum New To Java
    Replies: 6
    Last Post: 07-07-2012, 12:08 AM
  2. How to put Ints into Arrays..
    By NewToJava1 in forum New To Java
    Replies: 12
    Last Post: 04-21-2012, 10:08 PM
  3. Sum of odd ints 0-n
    By falkon114 in forum New To Java
    Replies: 7
    Last Post: 12-06-2010, 08:36 AM
  4. Help with ints
    By Insomniac Riot in forum New To Java
    Replies: 5
    Last Post: 04-02-2010, 03:53 PM
  5. GUI's and inputting doubles or ints
    By lopder1 in forum New To Java
    Replies: 19
    Last Post: 11-05-2009, 08:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •