ANDing Shorts

Posted on 2005-03-01
Medium Priority
Last Modified: 2010-03-31
Please help - very frustrated

The following code:

      short test1;
      short test2;
      short test3;

      test1 = 0x34;
      test2 = 0x00ff;
      test3 = test1&test2;

Produces the following error:

test.java:383: possible loss of precision
found   : int
required: short
        test3 = test1&test2;
1 error

Question by:Moskaluke
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
LVL 37

Expert Comment

ID: 13433834
  test3 = (short) (test1&test2);

Author Comment

ID: 13433862
Nope - Same error.  Thanks for getting back quick.
LVL 37

Expert Comment

ID: 13433871
>> Nope - Same error.
Well, I reproduced the exact error message.
But by adding that casting it has gone.
Sure you have that right?
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 37

Expert Comment

ID: 13433875
Did you put (test1&test2) between brackets?
LVL 37

Accepted Solution

zzynx earned 500 total points
ID: 13433880
>> Did you put (test1&test2) between brackets?
I think you didn't.
If you didn't, you just cast test1 to short (which it is already)

Author Comment

ID: 13433916
Sorry -
Yes - I missed the braces around test1&test2

Thank you very much.
LVL 37

Expert Comment

ID: 13433937
>> Thank you very much.
You're welcome

Thanks for accepting

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month10 days, 4 hours left to enroll

762 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