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

  • Home
  • SEARCH
  • 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 9015307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:43:08+00:00 2026-06-16T03:43:08+00:00

I have written the following code but findbugs is shwowing this error: BIT_ADD_OF_SIGNED_BYTE .

  • 0

I have written the following code but findbugs is shwowing this error: BIT_ADD_OF_SIGNED_BYTE. I tried a lot but may be I am not getting the concept of left shift correctly.

void problem() {
    byte [] byteArray = {1, 2, 3, 4, 5};
    int localOne = 0;
    for(int i = 0; i < 4; i++) {
        localOne = (localOne<<8) + byteArray[i]; 
    }
}
  • 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-16T03:43:09+00:00Added an answer on June 16, 2026 at 3:43 am

    You’r doing the shift correctly, your (possible) error is when adding a signed byte to an int

    Because of sign extension you need to do this:

    localOne = (localOne<<8) + (0xFF & byteArray[i]); 
    

    Say you have the byte 80 (hex), which is 1000 0000 (binary), this is -128 (decimal) because of the two’s complement representation. Now, when adding it to an int it first gets converted to an int. The resulting int is not

    0000 0000  0000 0000  0000 0000  1000 0000
    

    (binary) it will be

    1111 1111  1111 1111  1111 1111  1000 0000
    

    (binary) because of sign extension. To get the first, you have to apply a bitwise and with 0xFF wich is this in binary:

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

Sidebar

Related Questions

I have written the following code. But it is removing only &nbsp; not <br>
I have written the following code which will does not work but the second
I have written the following code to plot a graph but it is not
I have written the following code and getting the below error, I believe its
I have written the following code but the components of tabs are not shown....in
i have written the following code but it is giving parse error . here
I have written following code for the client of RMI. But getting java.rmi.ConnectException: Connection
I have written following code to pass File1 variable to Javascript, but its not
I have following code written to run NSTimer . But the NSTimer selector is
I have written the following code which works, but im wondering can I make

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.