Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7625719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:13:44+00:00 2026-05-31T05:13:44+00:00

i have a question for call management. I get a message with a payload

  • 0

i have a question for call management.

I get a message with a payload of 3 bytes in a byte[]. Different bits in there leads to calling another method. I did it with a logical AND between the byte and a shiftet 1 to get the value of the bit. I used if elseif etc. to call the specific method. Is there another possibilty to realise it, maybe a HashMap or something?

At least im forced to use max. Java 1.4

Greetings,
fnobbi

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:13:44+00:00Added an answer on May 31, 2026 at 5:13 am

    It depends on how many different methods you are calling. If it’s less than (I’m guessing here) 20, I would use simple bit-mask tests on a int (which is 4 bytes – use the lower 3) with if().

    For example:

    public static void callMethod(byte[] bytes) {
        int bits = (bytes[2] & 0xFF) << 16 +
                   (bytes[1] & 0xFF) << 8 + 
                   (bytes[0] & 0xFF);
        if ((bits & 1) > 0) {
            methodForBit0Set(bytes);
        }
        if ((bits & 2) > 0) {
            methodForBit1Set(bytes);
        }
        if ((bits & 4) > 0) {
            methodForBit3Set(bytes);
        }
        // etc
    }
    

    If you’re only calling one method then stopping, you’ll want to use elses between the ifs, and may also want to order the tests in order of most-frequently expected first.

    Using a hashmap wouldn’t be that much faster than these extremely fast operations IMHO even if you have lots of tests, and this is easier to read, debug and maintain.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this question: How could I call a codebehind method from jquery? I
Hopefully an easy question. If I have an object and I want to call
I have a quick question regarding memory management that I am not quite sure
I have a question about the memory management. In my app delegate, I have
i have a question about memory management.I have an instance variable that I previously
I have a little question with memory management is iOS... Well I define a
I have couple questions regarding some C++ rules. Why am I able to call
I have question regarding the SQLAlchemy. How can I add into my mapped class
I have question regarding the use of function parameters. In the past I have
I have question concerning a function I created. I would like to show the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.