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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:27:45+00:00 2026-06-19T02:27:45+00:00

Let’s take Byte.parseByte() as an example as one of the wrappers’ parseXXX() . From

  • 0

Let’s take Byte.parseByte() as an example as one of the wrappers’ parseXXX().

From parseByte(String s, int radix)'s JavaDoc:

Parses the string argument as a signed byte in the radix specified by
the second argument.

But that’s not quite true if radix = 2. In other words, the binary literal of -127 is 10000000:

byte b = (byte) 0b10000000;

So the following should be true:

byte b = Byte.parseByte("10000000", 2);

but unfortunately, it throws NumberFormatException, and instead I have to do it as follows:

byte b = Byte.parseByte("-111111", 2);

where parseByte() parses the binary string as a sign-magnitude (the sign and the magnitude), where it should parse as a signed binary (2’s complement, i.e. MSB is the sign-bit).

Am I wrong about this?

  • 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-19T02:27:46+00:00Added an answer on June 19, 2026 at 2:27 am

    Am I wrong about this?

    Yes. The Javadoc says nothing about 2’s-complement. Indeed, it explicitly states how it recognises negative values (i.e. a - prefix, so effectively “human-readable” sign-magnitude).

    Think about it another way. If parseByte interpreted radix-2 as 2’s-complement, what would you want it to do for radix-10 (or indeed, any other radix)? For consistency, it would have to be 10’s-complement, which would be inconvenient, I can assure you!

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

Sidebar

Related Questions

Let's have an example like below: package xliiv.sandbox; import android.app.Activity; import android.os.Bundle; import android.util.Log;
Let me explain best with an example. Say you have node class that can
Let me try to explain by example. Say website is hosted at example.com (NOT
Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
let's say I have the following string: string s = A B C D
Let's say I have one class User, and it has a property of type
Let's say I wanted to remove vowels from HTML: <a href=foo>Hello there!</a>Hi! becomes <a
let's say.. I have the following java bean. Case1: (Student Bean) Integer id; String
Let's say I got this string: $str = alemylaife; (I know it's misspelled, all
Let's say I get a PreparedStatement from a Connection object, and then later I

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.