C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 02-04-2006, 05:03 AM   #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.
Coder87C is offline   Reply With Quote
Old 02-04-2006, 05:33 AM   #2
+++ OK NO CARRIER
 
quzah's Avatar
 
Join Date: Oct 2001
Posts: 10,640
My guess is it wants you to cast your hex values to a short, but I don't C#.


Quzah.
__________________
Hundreds of thousands of dipshits can't be wrong.


Are you up for the suck?
quzah is offline   Reply With Quote
Old 02-04-2006, 05:43 AM   #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?
Coder87C is offline   Reply With Quote
Old 02-04-2006, 06:54 PM   #4
+++ OK NO CARRIER
 
quzah's Avatar
 
Join Date: Oct 2001
Posts: 10,640
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.
__________________
Hundreds of thousands of dipshits can't be wrong.


Are you up for the suck?
quzah is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing Structures Inside Structures Mellowz C Programming 1 01-13-2008 03:55 AM
Help calling function is asm brietje698 C++ Programming 24 12-06-2007 04:48 PM
Say what? - Weird error. Blackroot C++ Programming 6 08-15-2006 11:54 PM
Does Anybody Know How I Could Get The Date (In Short Format) rocky8015 C Programming 4 06-07-2005 10:57 AM
Color Variety Unregistered C++ Programming 7 10-23-2002 09:17 AM


All times are GMT -6. The time now is 12:03 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22