Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ushort bitmask "cannot implicitly convert type 'int' to 'ushort'

Posted on 2011-09-15
2
Medium Priority
?
985 Views
Last Modified: 2012-06-27
I can do this:
      ushort x = 0xFFFF;
      ushort y = x;
      y &= 0x01FF;

Open in new window

but I can't do this:
      ushort y = x & 0x01FF;

Open in new window

I get the error: Cannot implicitly convert type 'int' to 'ushort'. An explicit conversion exists (are you missing a cast?)

I try throwing in casts but Visual Studio still complains:
      ushort y = (ushort)x & (ushort)0x01FF;

Open in new window

What is the proper syntax for this?
0
Comment
Question by:deleyd
2 Comments
 
LVL 19

Accepted Solution

by:
Raheman M. Abdul earned 500 total points
ID: 36542477
Try
 ushort y = (ushort) (x & 0x01FF);
0
 
LVL 3

Assisted Solution

by:russellC
russellC earned 500 total points
ID: 36542504
Try:
ushort z = (ushort)(x & y);   // OK: explicit conversion
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question