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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:33:09+00:00 2026-06-18T07:33:09+00:00

I have a 3 byte signed number that I need to determine the value

  • 0

I have a 3 byte signed number that I need to determine the value of in Java. I believe it is signed with one’s complement but I’m not 100% sure (I haven’t studied this stuff in more than 10 years and the documentation of my problem isn’t super clear). I think the problem I’m having is Java does everything in two’s complement. I have a specific example to show:

  • The original 3-byte number: 0xEE1B17

  • Parsed as an integer (Integer.parseInt(s, 16)) this becomes: 15604503

  • If I do a simple bit flip (~) of this I get (I think) a two’s complement representation: -15604504

  • But the value I should be getting is: -1172713

What I think is happening is I’m getting the two’s complement of the entire int and not just the 3 bytes of the int, but I don’t know how to fix this.

What I have been able to do is convert the integer to a binary string (Integer.toBinaryString()) and then manually “flip” all of the 0s to 1s and vice-versa. When then parsing this integer (Integer.parseInt(s, 16)) I get 1172712 which is very close. In all of the other examples I need to always add 1 to the result to get the answer.

Can anyone diagnose what type of signed number encoding is being used here and if there is a solution other than manually flipping every character of a string? I feel like there must be a much more elegant way to do this.

EDIT: All of the responders have helped in different ways, but my general question was how to flip a 3-byte number and @louis-wasserman answered this and answered first so I’m marking him as the solution. Thanks to everyone for the help!

  • 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-18T07:33:10+00:00Added an answer on June 18, 2026 at 7:33 am

    If you want to flip the low three bytes of a Java int, then you just do ^ 0x00FFFFFF.

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

Sidebar

Related Questions

I have a byte array, received from java application via network. I need to
I have this method that converts a signed or non-signed byte to int ,
I have a signed file uploader applet that works in Chrome but seems to
I have a specific C bit-shifting scenario that I do not believe is covered
I have an array of bytes that correspond to a grayscaled bitmap (one byte->one
I have the following Java code: byte value = 0xfe; // corresponds to -2
Why do computers have byte-addressable memory, and not 4-byte-addressable memory (or 8-byte-addressable memory for
I have a byte array and I need to convert this to a image.
I have a byte[] that i obtained using Object ArrayList<Obj> Can anyone tell me
I have a byte[] of an image and I need to upload it as

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.