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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:11:15+00:00 2026-05-23T18:11:15+00:00

I have a hex string that represents a 2’s complement number. Is there an

  • 0

I have a hex string that represents a 2’s complement number. Is there an easy way (libraries/functions) to translate the hex into a decimal without working directly with its bits??

E.G. This is the expected output given the hex on the left:

"0000" => 0
"7FFF" => 32767 (max positive number)
"8000" => -32768 (max negative number)
"FFFF" => -1

Thanks!

  • 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-23T18:11:15+00:00Added an answer on May 23, 2026 at 6:11 pm

    This seems to trick java into converting the number without forcing a positive result:

    Integer.valueOf("FFFF",16).shortValue(); // evaluates to -1 (short)
    

    Of course this sort of thing only works for 8, 16, 32, and 64-bit 2’s complement:

    Short.valueOf("FF",16).byteValue(); // -1 (byte)
    Integer.valueOf("FFFF",16).shortValue(); // -1 (short)
    Long.valueOf("FFFFFFFF",16).intValue(); // -1 (int)
    new BigInteger("FFFFFFFFFFFFFFFF",16).longValue(); // -1 (long)
    

    Example here.

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

Sidebar

Related Questions

Let's say that I have a string 5a . This is the hex representation
I have a number (hex) and I want the one's complement of it. For
I have a Hex String 40 that i would like to convert to its
I have a hex-string made from a unicode string with that function: def toHex(s):
I have a long sequence of hex digits in a string, such as 000000000000484240FA063DE5D0B744ADBED63A81FAEA390000C8428640A43D5005BD44
I have a twenty byte hex hash that I would like to store in
We have a J2ME application that needs to read hex numbers. The application is
I need to make a string representation of a 128bit GUID that represents 8bit
I have a hex string and i want to convert it utf8 to insert
i have a very long hex string in a byte array and I would

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.