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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:22:26+00:00 2026-05-27T23:22:26+00:00

i need some help improving the following code – there is a conversion between

  • 0

i need some help improving the following code – there is a conversion between byte and int, that does not work in all cases – I need some feedback to find and solve possible issues involving byteToInt IntToByte conversion

int start = 02;
int stepSize = 256;
int bytesLeftToRead = 
// [0][1] encode a hex value as two bytes
// this part only works for [0] > 0 and [0] < 10 -- other restrictions?
response[0]*256 + Integer.parseInt(Integer.toHexString(response[1] + 256), 16);

while(bytesLeftToRead > 0){

    // convert where to start from int to two bytes
    cmdReadPD[2] = (byte) (start / 256);
    cmdReadPD[3] = (byte) (start % 256);

    if(stepSize > bytesLeftToRead){
        stepSize = bytesLeftToRead;
    }

    // encode stepsize in two bytes
    cmdReadPD[5] = (byte) (stepSize / 256);
    cmdReadPD[6] = (byte) (stepSize % 256);

    start += stepSize;
    bytesLeftToRead -= stepSize;
    read(cmdReadPD, stepSize);
}
  • 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-27T23:22:26+00:00Added an answer on May 27, 2026 at 11:22 pm

    Use (byte) ((start >> 8) & 0xFF); and (byte) (start & 0xFF);.

    Note though it will only help for ints lower than 2^16.

    To recollect bytes to int, use (lo & 0xFF) | ((hi & 0xff) << 8): & will widen the byte to an int, making negative bytes positive ints; shift and | will recollect the value.

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

Sidebar

Related Questions

need some help! I'm trying to write some code in objective-c that requires part-of-speech
Need some help assigning a mouseover event to display some icons that start out
I need some help from the shell-script gurus out there. I have a .txt
I need some help regarding algorithm for randomness. So Problem is. There are 50
Need some help, I have a regular expression that appears to work just fine
Need some help to write a C# code to send mail to multiple users
Need some help refactoring this if/else block that builds the conditions for a find
I need some help improving this function I made for parsing the links in
I need help with improving the performance of the following SQL query. The database
Need some help with extracting 2 pieces of information from the following string: viewed

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.