Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now