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 8011739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:06:21+00:00 2026-06-04T19:06:21+00:00

I have a Java method which has to execute a block of code many

  • 0

I have a Java method which has to execute a block of code many times:

            // Obtengo los 7 bits de direccion
            clockStateIndex = dataStateIndex;
            for(int bit = 7; bit > 0; --bit){           
                clockStateIndex = clockSource.nextClearBit(clockStateIndex);                    // Siguiente bit en SCL
                clockStateIndex = clockSource.nextSetBit(clockStateIndex);
                testIndex = (clockSource.nextClearBit(clockStateIndex) - clockStateIndex)/2;    // Busco la mitad del bit clock
                bitSet(direccion, data.get(testIndex), bit);                // Compruebo SDA en la mitad del bit SCL
            }
            // Obttengo el bit R/W
            clockStateIndex = clockSource.nextClearBit(clockStateIndex);    // Siguiente bit en SCL
            clockStateIndex = clockSource.nextSetBit(clockStateIndex);
            testIndex = (clockSource.nextClearBit(clockStateIndex) - clockStateIndex)/2;    // Busco la mitad del bit clock
            rwBit = data.get(testIndex);        // Obtengo el estado del bit R/W en el medio del bit SCL

            // Obtengo el bit de ACK
            clockStateIndex = clockSource.nextClearBit(clockStateIndex);    // Siguiente bit en SCL
            clockStateIndex = clockSource.nextSetBit(clockStateIndex);
            testIndex = (clockSource.nextClearBit(clockStateIndex) - clockStateIndex)/2;    // Busco la mitad del bit clock
            ackBit = data.get(testIndex);       // Obtengo el estado del bit R/W en el medio del bit SCL

            // Si tengo un ACK obtengo los 8 bits de dato
            if(ackBit == false){
                for(int bit = 8; bit > 0; --bit){           
                    clockStateIndex = clockSource.nextClearBit(clockStateIndex);    
                    clockStateIndex = clockSource.nextSetBit(clockStateIndex);
                    testIndex = (clockSource.nextClearBit(clockStateIndex) - clockStateIndex)/2;    
                    bitSet(i2cData, data.get(testIndex), bit);      
                }
            }

As you can see the code:

clockStateIndex = clockSource.nextClearBit(clockStateIndex);    
clockStateIndex = clockSource.nextSetBit(clockStateIndex);
testIndex = (clockSource.nextClearBit(clockStateIndex) - clockStateIndex)/2;    

Is repeated lot of times. I cannot create #defines to simplify my code doing something like nextBit(); to replace that code. Is there any other way to simplify it ?
If a create a method i will have to pass two BitSet which size is about 200 elements and return 2 int elements (i dont know hot to do it in Java because i dont have pointers like in C)

Hope you can help me 🙂

  • 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-06-04T19:06:22+00:00Added an answer on June 4, 2026 at 7:06 pm

    I would wrap it in a function:

    // Instance based (inside classes)
    {SCOPE MODIFIER} void ClockWork()
    {
        clockStateIndex = clockSource.nextClearBit(clockStateIndex);    
        clockStateIndex = clockSource.nextSetBit(clockStateIndex);
        testIndex = (clockSource.nextClearBit(clockStateIndex) - clockStateIndex) / 2;  
    }
    

    As for a static based method, it depends on where you are implementing the code.

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

Sidebar

Related Questions

Presently I have a code that has a java main method and which takes
Java Code In Java code I have class called IdentificationResult which has 3 members:
I have to implement one web2py application which has to access java code (which
I have a JNI method to access java method which returns an Integer object.
Let's say I have a java.util.Properties object. The Properties object has a method called
lets say i have a method which has two parameters. i have been implementing
This seems a basic java question. I have one interface, Pipeline , which has
I have an java EE application which has one message-driven bean and it runs
I have a web application which uses Ajax for several tasks. It has Java
I have a java method activated by a mouse click on a button private

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.