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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:20:18+00:00 2026-05-28T02:20:18+00:00

As you know, the binary literal is a new feature that is introduced in

  • 0

As you know, the binary literal is a new feature that is introduced in Java 7:

int x = 0b1011;
System.out.println(x); // prints 11 as expected

But, when I tried to get the maximum number from the literal binary I got -1!!!

int x = 0b11111111111111111111111111111111;
System.out.println(x); // prints -1 !!!

Further Details:

System.out.println(Integer.MAX_VALUE);
System.out.println(0b1111111111111111111111111111111); // 31 bits

/* Both print 2147483647 */

/************************************************************************************/

System.out.println(Integer.MIN_VALUE);
System.out.println(0b10000000000000000000000000000000); // 32 bits (increment by 1)

/* Both print -2147483648 */

/************************************************************************************/

// And if you keep increasing the binary literal, its actual value
// will be decreased until you reach the maximum binary literal and
// its actual value will be -1.

System.out.println(0b11111111111111111111111111111111); // 32 bits

/* Prints -1 */

As you can see, the actual value of the literal binary (while the increment) jumps over from the maximum value of int to the minimum one and then keep decreasing till it reaches -1 which is the maximum value of the literal binary.

Is this a bug? or does it have something to do with signed/unsigned numbers?

  • 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-28T02:20:18+00:00Added an answer on May 28, 2026 at 2:20 am

    You’re using a signed integer. Bit 32 (the “first” one from the left) is the sign bit. It being 1 means it is a negative number, and 0 means positive. Two’s complement is then performed to give the value of -1. Read about that here:

    http://tfinley.net/notes/cps104/twoscomp.html

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

Sidebar

Related Questions

I know that the following is true int i = 17; //binary 10001 int
I know that google's v8 compiles javascript into native machine (binary if I understand
1-)For sorted array I have used Binary Search. We know that the worst case
I know that OCIE0A=0001 in binary, so would (1<<OCIE0A) just be 0010? I see
I know that there are many binary operations to show that something is true
I know that I should open a binary file using rb instead of r
Ok,so I know that the binary equivalent of 104 is 1101000. 10=1010 4=0100 so
I know that SortedDictionary is a binary search tree (and it can almost do
I know that if I use binary serialization with WCF I lose interopability. If
i know that if 1 is present at the 4th position of binary representation

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.