Thread: Short to 16bit 555 format

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    110

    Short to 16bit 555 format

    Hi,

    I have a file which I read in shorts. Each short represents a color.

    I need to make the short into a RGB color using 555 format.

    F = Alpha
    Red = E to A
    Green = 9 to 5
    Blue = 4 to 0.

    So I made the function

    Code:
    public Color getColor(short value)
        {
            short R = (value & 0xF800) >> 10;
            short G = (value & 0x07C0) >> 5;
            short B = (value & 0x003E);
            return Color.FromArgb(R, G, B);
        }
    The error I get is:

    Error 1 Cannot implicitly convert type 'int' to 'short'. An explicit conversion exists (are you missing a cast?)

    On each of the conversions. I looked this up in a couple places and it said almost the same thing, can anyone help me?

    Thankyou.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    My guess is it wants you to cast your hex values to a short, but I don't C#.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    110
    What I did was changed it to:

    int R = (value & 0xF800) >> 10;

    so int R not short R.

    Can this screw things up?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    That depends if you really need a short or an int. In C you'd just do something like this, that is, if you really needed to:
    Code:
    short int R = (value & (short int)0xABC) >> 10;
    I've never looked at C# so I don't know how they do casts.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Accessing Structures Inside Structures
    By Mellowz in forum C Programming
    Replies: 1
    Last Post: 01-13-2008, 03:55 AM
  2. Help calling function is asm
    By brietje698 in forum C++ Programming
    Replies: 24
    Last Post: 12-06-2007, 04:48 PM
  3. Say what? - Weird error.
    By Blackroot in forum C++ Programming
    Replies: 6
    Last Post: 08-15-2006, 11:54 PM
  4. Replies: 4
    Last Post: 06-07-2005, 10:57 AM
  5. Color Variety
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 10-23-2002, 09:17 AM