Results 1 to 19 of 19

Thread: Integer to Hexadecimal

  1. #1

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    Integer to Hexadecimal

    I am using a structure who has its three parameters declared as "COLOR16". I didn't find any documentation for it on MSDN but it says the value of COLOR16 can range from 0x0000 to 0xff00. This is hex but I have an integer that I want to pass it. Example:
    PHP Code:
    TRIVERTEX        vert[2] ;
    vert [0] .Red      GetRValue(mycolor);
    vert [0] .Green      GetGValue(mycolor);
    //..... 
    .Red and .Green are decalred as COLOR16. But GetRValue is either BYTE or int. It just doesn't work if I use the above method of typecast it like "(COLOR16)GetRValue(mycolor)". It only works if I provide a haxadecimal value.
    How can I make it work WITH a variable instead of just passing it a non-declared hex value?
    Baaaaaaaaah

  2. #2

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Hmmm, I just tried declaring the RGB values as COLOR16 but it still doesn't work.
    PHP Code:
        COLOR16 r1,  g1,  b1;
        
    r1 = (COLOR16)GetRValue(crColour1);
        
    g1 = (COLOR16)GetRValue(crColour1);
        
    b1 = (COLOR16)GetGValue(crColour1);
    TRIVERTEX        vert[2] ;
    vert [0] .x      0;
    vert [0] .y      0;
    vert [0] .Red    r1;
    vert [0] .Green  g1;
    vert [0] .Blue   b1;
    vert [0] .Alpha  0x0000;
    //....continued.... 
    Baaaaaaaaah

  3. #3
    DaoK
    Guest
    This might help, I haved tested it and it work if you change the int x =1 to unsigned int x =1

    http://planet-source-code.com/vb/scr...=4064&lngWId=3

  4. #4

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Nope, didn't work.
    Baaaaaaaaah

  5. #5
    DaoK
    Guest
    Why ? You just want to convert the number isn't?

  6. #6

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Yes, but I don't want to convert that number to a string which contains the hexdecimal value of it. Because there's no variable type of hold hexadecimal, I won't be able to store this number and then pass it as a colour.
    It's just weird that the structure isn't accepting any integer although it's happily using its hexadecimal form (0x....).
    Baaaaaaaaah

  7. #7
    jim mcnamara
    Guest
    COLOR16 is unsigned short (USHORT) - a two byte unsigned integer.

  8. #8

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    ya, it's USHORT after I looked at the wingdi.h header file. But how would I do the conversion?
    Baaaaaaaaah

  9. #9
    DaoK
    Guest
    Maybe what I will said it's idiot but you can not simply cast it?

  10. #10

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Yes, that's what I did but it didn't work.
    (COLOR16)GetRValue(crColour);
    Baaaaaaaaah

  11. #11
    Lively Member
    Join Date
    Jun 2002
    Posts
    81
    try using (USHORT)GetRValue(crColour);

  12. #12
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    What does GetRValue return?
    What is the error?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  13. #13

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    GetRValue returns a BYTE which is the value of red colour in a colour. I don't get any error but the function just does draw the correct gradient (it doesn't use the values I provide) unless I provide it a hex value (0x****).
    Baaaaaaaaah

  14. #14
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    from MSDN

    Code:
    //declaraction of GetRValue
    
    BYTE GetRValue(
      DWORD rgb  // RGB value
    );
    Just convert your parameter variables to DWORD will do.

    DWORD is double word, meaning it is unsigned integer(32bit) alias.

    For your FYI, hex, octal and based 10 representation are the same in binary so there is no reason that they cannot be interchangeable.

    The reason 0x**** works is bcos it is a constant implicitly casted into DWORD.

    When u put variables in, it couldn't work, meaning the variables u used cannot be cast into DWORD.

    Another reason is GetRValue takes it that (assuming u put in 16bit variable) every colour component in the parameter is 8 bit, but in 16bit variable, every colour compnent is not 8 bit, rather than 565, so when u put in 16bit(implictly casted and zero-extended to 32bit), GetRValue() extracts 8 bits(5 of red + 3 of green), insteads of 5bits for red.

    Of course, when u put in hex constants, it worked ,but in a wrong way for u.

    Do I make myself clear?

  15. #15
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    If u previously had put in a DWORD, then I have nothing to say.

  16. #16

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    There is no problem with GetRValue(). I returns the correct red value and I can use this value with many many other functions which also works. The only problem is that I can't assign this value to the structure I just talked about above because it takes it as COLOR16.
    Weird thing is that typecasting isn't work here either.
    Baaaaaaaaah

  17. #17
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    Why dun u just change the structure members, Red, Green and Blue to BYTE?

    You doesn't need them to be COLOR16, right?

  18. #18

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    The structure is defined in Windows API - not by me.
    Baaaaaaaaah

  19. #19
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You can't cast from different color systems just like that.
    You need to recalculate the values. e.g. if you have the color value 4 when 16 are possible, it becomes 16 when 64 are possible. You can't simply change their type.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width