Solved

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

Posted on 2011-09-15
2
916 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 18

Accepted Solution

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

Assisted Solution

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

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

809 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